add settings for YAML/TOML header #17
This commit is contained in:
@ -8,5 +8,9 @@
|
|||||||
// When the preview is opened, the markdown file is closed in the origin window and reopend in
|
// When the preview is opened, the markdown file is closed in the origin window and reopend in
|
||||||
// the preview window. If this option is set to 'true', then the markdown file will NOT be
|
// the preview window. If this option is set to 'true', then the markdown file will NOT be
|
||||||
// closed in the origin window
|
// closed in the origin window
|
||||||
"keep_open_when_opening_preview": false
|
"keep_open_when_opening_preview": false,
|
||||||
|
|
||||||
|
// Choose what to do with YAML/TOML (---/+++ respectively) headers
|
||||||
|
// Valid values: "wrap_in_pre", "remove".
|
||||||
|
"header_action": "wrap_in_pre"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,8 +48,12 @@ def get_style():
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
def markdown2html(md, basepath):
|
def markdown2html(md, basepath):
|
||||||
|
# removes/format the header.
|
||||||
|
md = manage_header(md, get_settings().get('header_action'))
|
||||||
|
|
||||||
html = '<style>\n{}\n</style>\n'.format(get_style())
|
html = '<style>\n{}\n</style>\n'.format(get_style())
|
||||||
|
|
||||||
|
|
||||||
# the option no-code-highlighting does not exists in the official version of markdown2 for now
|
# the option no-code-highlighting does not exists in the official version of markdown2 for now
|
||||||
# I personaly edited the file (markdown2.py:1743)
|
# I personaly edited the file (markdown2.py:1743)
|
||||||
html += md2.markdown(md, extras=['fenced-code-blocks', 'no-code-highlighting', 'tables'])
|
html += md2.markdown(md, extras=['fenced-code-blocks', 'no-code-highlighting', 'tables'])
|
||||||
|
|||||||
13
functions.py
13
functions.py
@ -11,12 +11,25 @@ def plugin_loaded():
|
|||||||
loading = sublime.load_resource('Packages/MarkdownLivePreview/loading.txt')
|
loading = sublime.load_resource('Packages/MarkdownLivePreview/loading.txt')
|
||||||
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
||||||
|
|
||||||
|
MATCH_YAML_HEADER = re.compile(r'^([\-\+])\1{2}\n(?P<content>.+)\n\1{3}\n', re.DOTALL)
|
||||||
|
|
||||||
def strip_html_comments(html):
|
def strip_html_comments(html):
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
for element in soup.find_all(text=lambda text: isinstance(text, html_comment)):
|
for element in soup.find_all(text=lambda text: isinstance(text, html_comment)):
|
||||||
element.extract()
|
element.extract()
|
||||||
return str(soup)
|
return str(soup)
|
||||||
|
|
||||||
|
def manage_header(md, action):
|
||||||
|
matchobj = MATCH_YAML_HEADER.match(md)
|
||||||
|
if not matchobj:
|
||||||
|
return md
|
||||||
|
if action == 'remove':
|
||||||
|
return md[len(matchobj.group(0)):]
|
||||||
|
elif action == 'wrap_in_pre':
|
||||||
|
return '<pre><code>' + matchobj.group('content') + '</code></pre>' \
|
||||||
|
+ md[len(matchobj.group(0)):]
|
||||||
|
|
||||||
|
raise ValueError('Got an unknown action: "{}"'.format(action))
|
||||||
|
|
||||||
def get_preview_name(md_view):
|
def get_preview_name(md_view):
|
||||||
file_name = md_view.file_name()
|
file_name = md_view.file_name()
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
---
|
---
|
||||||
title: Demo
|
title: Demo
|
||||||
description: Preview your markdown!
|
description: Preview your markdown right in Sublime Text!
|
||||||
|
hope: You'll enjoy using it!
|
||||||
---
|
---
|
||||||
|
|
||||||
# Hello world
|
# Hello world
|
||||||
|
|
||||||
<!-- supports comments -->
|
<!-- supports comments -->
|
||||||
@ -33,7 +35,7 @@ if you is moods.curious:
|
|||||||
| 45 | John |
|
| 45 | John |
|
||||||
| `<table>` | `><` |
|
| `<table>` | `><` |
|
||||||
|
|
||||||
[Sublime Text Logo](https://upload.wikimedia.org/wikipedia/en/4/4c/Sublime_Text_Logo.png)
|

|
||||||
|
|
||||||
Some plugin I just *need*:
|
Some plugin I just *need*:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user