Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add configurable pane direction. #368

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Markdown Preview package
[![macOS Build Status](https://travis-ci.org/atom/markdown-preview.svg?branch=master)](https://travis-ci.org/atom/markdown-preview) [![Windows Build Status](https://ci.appveyor.com/api/projects/status/bvh0evhh4v6w9b29/branch/master?svg=true)](https://ci.appveyor.com/project/Atom/markdown-preview/branch/master) [![Dependency Status](https://david-dm.org/atom/markdown-preview.svg)](https://david-dm.org/atom/markdown-preview)

Show the rendered HTML markdown to the right of the current editor using <kbd>ctrl-shift-m</kbd>.
Show the rendered HTML markdown next to the current editor using <kbd>ctrl-shift-m</kbd>.

It is currently enabled for `.markdown`, `.md`, `.mdown`, `.mkd`, `.mkdown`, `.ron`, and `.txt` files.

![markdown-preview](https://cloud.githubusercontent.com/assets/378023/10013086/24cad23e-6149-11e5-90e6-663009210218.png)

## Customize

You can choose in which direction to show the preview (`right` or `down`), or even to show the preview in a new tab in the current pane (`none`) by using the Split Pane Direction in the __package settings__.

By default Markdown Preview uses the colors of the active syntax theme. Enable `Use GitHub.com style` in the __package settings__ to make it look closer to how markdown files get rendered on github.com.

![markdown-preview GitHub style](https://cloud.githubusercontent.com/assets/378023/10013087/24ccc7ec-6149-11e5-97ea-53a842a715ea.png)
Expand Down
5 changes: 3 additions & 2 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ module.exports =
previousActivePane = atom.workspace.getActivePane()
options =
searchAllPanes: true
if atom.config.get('markdown-preview.openPreviewInSplitPane')
options.split = 'right'
splitPane = atom.config.get('markdown-preview.splitPaneDirection')
if splitPane isnt 'none'
options.split = splitPane
atom.workspace.open(uri, options).then (markdownPreviewView) ->
if isMarkdownPreviewView(markdownPreviewView)
previousActivePane.activate()
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"default": true,
"description": "Re-render the preview as the contents of the source changes, without requiring the source buffer to be saved. If disabled, the preview is re-rendered only when the buffer is saved to disk."
},
"openPreviewInSplitPane": {
"type": "boolean",
"default": true,
"description": "Open the preview in a split pane. If disabled, the preview is opened in a new tab in the same pane."
"splitPaneDirection": {
"type": "string",
"default": "right",
"enum": ["none", "right", "down"],
"description": "Whether to open the preview in a split pane, and if so the direction in which to open it. If `none`, the preview is opened in a new tab in the same pane."
},
"allowUnsafeProtocols": {
"type": "boolean",
Expand Down
33 changes: 29 additions & 4 deletions spec/markdown-preview-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ temp = require('temp').track()
MarkdownPreviewView = require '../lib/markdown-preview-view'

describe "Markdown Preview", ->
previewPane = null
preview = null

beforeEach ->
Expand All @@ -24,21 +25,45 @@ describe "Markdown Preview", ->
runs ->
spyOn(atom.packages, 'hasActivatedInitialPackages').andReturn true

expectPreviewInSplitPane = ->
expectPreviewInSplitPane = (orientation='horizontal') ->
waitsFor -> atom.workspace.getCenter().getPanes().length is 2

waitsFor "markdown preview to be created", ->
preview = atom.workspace.getCenter().getPanes()[1].getActiveItem()
previewPane = atom.workspace.getCenter().getPanes()[1]
preview = previewPane.getActiveItem()

runs ->
expect(preview).toBeInstanceOf(MarkdownPreviewView)
expect(preview.getPath()).toBe atom.workspace.getActivePaneItem().getPath()
expect(previewPane.getParent().getOrientation()).toBe orientation

describe "when a preview has not been created for the file", ->
it "displays a markdown preview in a split pane", ->
it "displays a markdown preview in a split pane (right by default)", ->
waitsForPromise -> atom.workspace.open("subdir/file.markdown")
runs -> atom.commands.dispatch atom.workspace.getActiveTextEditor().getElement(), 'markdown-preview:toggle'
expectPreviewInSplitPane()
expectPreviewInSplitPane('horizontal')

runs ->
[editorPane] = atom.workspace.getPanes()
expect(editorPane.getItems()).toHaveLength 1
expect(editorPane.isActive()).toBe true

it "displays a markdown preview in a split pane (right)", ->
atom.config.set 'markdown-preview.splitPaneDirection', 'right'
waitsForPromise -> atom.workspace.open("subdir/file.markdown")
runs -> atom.commands.dispatch atom.workspace.getActiveTextEditor().getElement(), 'markdown-preview:toggle'
expectPreviewInSplitPane('horizontal')

runs ->
[editorPane] = atom.workspace.getPanes()
expect(editorPane.getItems()).toHaveLength 1
expect(editorPane.isActive()).toBe true

it "displays a markdown preview in a split pane (down)", ->
atom.config.set 'markdown-preview.splitPaneDirection', 'down'
waitsForPromise -> atom.workspace.open("subdir/file.markdown")
runs -> atom.commands.dispatch atom.workspace.getActiveTextEditor().getElement(), 'markdown-preview:toggle'
expectPreviewInSplitPane('vertical')

runs ->
[editorPane] = atom.workspace.getCenter().getPanes()
Expand Down