From ccb838c4f55adde5bb55298f635a74542fe8e515 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 15 Nov 2016 12:15:11 -0500 Subject: improve editor --- enhancers.txt | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/enhancers.txt b/enhancers.txt index 22c684b..d70a5f8 100644 --- a/enhancers.txt +++ b/enhancers.txt @@ -23,36 +23,77 @@ X-Thing: Tail tip.innerHTML = '

Tip: To set the page title (what appears in the tab '+ 'name/window bar), put this at the top of the page:

\n'+ - '
---\ntitle: "Your Title Here"\n---\n
'+ - '

I apologize that it looks funny on this page and in the '+ - 'preview.

'; + '
---\ntitle: "Your Title Here"\n---\n
\n'+ + + '

(I apologize that it looks funny on this page and in the '+ + 'preview.)

\n'+ + + '

Otherwise, the first line will be used as the title. This means '+ + 'that if you want the title to also appear at the top of the document, '+ + 'you can instead use:

\n'+ + '

Your Title Here\n===============\n
\n'+ + '

which will also include it as a heading at the top of the page.

'; + container.appendChild(tip); + // bug workaround from https://github.com/codemirror/CodeMirror/issues/2143#issuecomment-140100969 + var updateSectionHeaderStyles = function(cm, change) { + var lines = cm.lineCount(); + for (var i = Math.max(0, change.from.line-1); i <= Math.min(change.to.line+1, lines-1); i++) { + var line = cm.getLineHandle(i); + cm.removeLineClass(line, 'text', 'cm-header'); + cm.removeLineClass(line, 'text', 'cm-header-1'); + cm.removeLineClass(line, 'text', 'cm-header-2'); + var lineTokens = cm.getLineTokens(i); + var tok = lineTokens[0]; + if (!tok || !tok.type || tok.type.indexOf('header') === -1) { + // first token could be some spaces, try 2nd + tok = lineTokens[1]; + } + if (tok && tok.type && tok.type.indexOf('header') !== -1 + && tok.string !== '#') { // not ATX header style, which starts with # + var classes = tok.type. + split(' '). + filter(function(cls) { return cls.indexOf('header') === 0; }). + map(function (cls) { return 'cm-' + cls; }). + join(' '); + var prev_line = cm.getLineHandle(i-1); + cm.addLineClass(prev_line, 'text', classes); + } + } + }; + var simplemde = new SimpleMDE({ autoDownloadFontAwesome: false, element: textarea, promptURLs: true, - forceSync: true, showIcons: ['code', 'table'], }); + var cm = simplemde.codemirror; + cm.on("change", function(cm, change) { + cm.save(); // this is SimpleMDE forceSync + updateSectionHeaderStyles(cm, change); + }); + updateSectionHeaderStyles(cm, {from: {line: 0}, to: {line: cm.lineCount()}}); })(); --boundary X-Thing: Pattern -text/*; */*+xml +text/*; */*+xml; application/x-ruby --boundary X-Thing: Head - + + @@ -79,7 +120,7 @@ X-Thing: Tail lineNumbers: true, matchBrackets: true, foldGutter: true, - rulers: [{column: 80, lineStyle: "dashed"}], + rulers: [{column: 72, color: '#DDDDDD', lineStyle: "dashed"}, {column: 80, color: '#F4DDDD', lineStyle: "dashed"}], showTrailingSpace: true, gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], }); -- cgit v1.2.3-54-g00ecf