|
Lines 25-33
Link Here
|
| 25 |
'orion/webui/littlelib', |
25 |
'orion/webui/littlelib', |
| 26 |
'orion/URITemplate', |
26 |
'orion/URITemplate', |
| 27 |
'orion/webui/splitter', |
27 |
'orion/webui/splitter', |
|
|
28 |
'orion/editor/stylers/text_x-yaml/syntax', |
| 28 |
'orion/metrics', |
29 |
'orion/metrics', |
| 29 |
'orion/URL-shim' |
30 |
'orion/URL-shim' |
| 30 |
], function(i18nUtil, messages, marked, mCommands, mKeyBinding, mAnnotations, mEditor, mTextStyler, mTextUtil, mFileCommands, objects, lib, URITemplate, mSplitter, mMetrics) { |
31 |
], function(i18nUtil, messages, marked, mCommands, mKeyBinding, mAnnotations, mEditor, mTextStyler, mTextUtil, mFileCommands, objects, lib, URITemplate, mSplitter, mYAML, mMetrics) { |
| 31 |
|
32 |
|
| 32 |
var uriTemplate = new URITemplate("#{,resource,params*}"); //$NON-NLS-0$ |
33 |
var uriTemplate = new URITemplate("#{,resource,params*}"); //$NON-NLS-0$ |
| 33 |
var extensionRegex = /\.([0-9a-z]+)(?:[\?#]|$)/i; |
34 |
var extensionRegex = /\.([0-9a-z]+)(?:[\?#]|$)/i; |
|
Lines 107-113
Link Here
|
| 107 |
return string; |
108 |
return string; |
| 108 |
} |
109 |
} |
| 109 |
|
110 |
|
| 110 |
var MarkdownStylingAdapter = function(model, resource, fileClient) { |
111 |
var MarkdownStylingAdapter = function(model, editor, resource, fileClient) { |
| 111 |
this.model = model; |
112 |
this.model = model; |
| 112 |
this._blocksCache = {}; |
113 |
this._blocksCache = {}; |
| 113 |
this._defBlocks = {}; |
114 |
this._defBlocks = {}; |
|
Lines 116-121
Link Here
|
| 116 |
/* relativize marked's outputLink */ |
117 |
/* relativize marked's outputLink */ |
| 117 |
var resourceURL = new URL(resource, window.location.href); |
118 |
var resourceURL = new URL(resource, window.location.href); |
| 118 |
marked.InlineLexer.prototype.outputLink = filterOutputLink(resourceURL, fileClient, resource.indexOf(":") === -1); //$NON-NLS-0$ |
119 |
marked.InlineLexer.prototype.outputLink = filterOutputLink(resourceURL, fileClient, resource.indexOf(":") === -1); //$NON-NLS-0$ |
|
|
120 |
|
| 121 |
/* for styling YAML front-matters */ |
| 122 |
this._yamlStylerAdapter = new mTextStyler.createPatternBasedAdapter(mYAML.grammars, "orion.yaml", "text/x-yaml"); //$NON-NLS-1$ //$NON-NLS-0$ |
| 123 |
this._yamlStyler = new mTextStyler.TextStyler(editor.getTextView(), editor.getAnnotationModel(), this._yamlStylerAdapter); |
| 119 |
|
124 |
|
| 120 |
this._inlinePatterns = []; |
125 |
this._inlinePatterns = []; |
| 121 |
var patternIndex = 0; |
126 |
var patternIndex = 0; |
|
Lines 155-168
Link Here
|
| 155 |
block.seedTokens = null; |
160 |
block.seedTokens = null; |
| 156 |
} |
161 |
} |
| 157 |
|
162 |
|
| 158 |
var index = 0; |
163 |
/* handle YAML front-matter specially */ |
|
|
164 |
if (!offset) { |
| 165 |
var match = this._yamlStylerAdapter._findMatch(this._yamlFrontMatterRegex, text, 0); |
| 166 |
if (match && !match.index) { |
| 167 |
var endMatch = this._yamlStylerAdapter._findMatch(this._yamlFrontMatterRegex, text, match.length + 1); |
| 168 |
if (endMatch) { |
| 169 |
var end = endMatch.index + endMatch[0].length; |
| 170 |
var newBlock = |
| 171 |
this._yamlStylerAdapter.createBlock({ |
| 172 |
start: 0, |
| 173 |
contentStart: match[0].length, |
| 174 |
contentEnd: endMatch.index, |
| 175 |
end: end |
| 176 |
}, |
| 177 |
this._yamlStyler, |
| 178 |
model, |
| 179 |
block |
| 180 |
); |
| 181 |
newBlock.name = newBlock.typeId = newBlock.elementId = this._YAML_FRONTMATTER; |
| 182 |
result.push(newBlock); |
| 183 |
text = text.substring(end); |
| 184 |
offset = end; |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 159 |
tokens = tokens || marked.lexer(text, markedOptions); |
189 |
tokens = tokens || marked.lexer(text, markedOptions); |
|
|
190 |
var index = 0; |
| 160 |
|
191 |
|
| 161 |
for (var i = 0; i < tokens.length; i++) { |
192 |
for (var i = 0; i < tokens.length; i++) { |
| 162 |
var bounds = null, name = null, end = null, newlines = null; |
193 |
var bounds = null, name = null, newlines = null; |
| 163 |
var startToken = null, contentToken = null, parentTokens = null, endToken = null; |
194 |
var startToken = null, contentToken = null, parentTokens = null, endToken = null; |
| 164 |
var seedTokens = null; |
195 |
var seedTokens = null; |
| 165 |
|
196 |
end = null; |
| 166 |
name = null; |
197 |
name = null; |
| 167 |
this._whitespaceRegex.lastIndex = index; |
198 |
this._whitespaceRegex.lastIndex = index; |
| 168 |
var whitespaceResult = this._whitespaceRegex.exec(text); |
199 |
var whitespaceResult = this._whitespaceRegex.exec(text); |
|
Lines 172-178
Link Here
|
| 172 |
|
203 |
|
| 173 |
if (tokens[i].type === "heading") { //$NON-NLS-0$ |
204 |
if (tokens[i].type === "heading") { //$NON-NLS-0$ |
| 174 |
this._atxDetectRegex.lastIndex = index; |
205 |
this._atxDetectRegex.lastIndex = index; |
| 175 |
var match = this._atxDetectRegex.exec(text); |
206 |
match = this._atxDetectRegex.exec(text); |
| 176 |
var isAtx = match && match.index === index; |
207 |
var isAtx = match && match.index === index; |
| 177 |
var lineEnd = this._getLineEnd(text, index, model); |
208 |
var lineEnd = this._getLineEnd(text, index, model); |
| 178 |
end = isAtx ? lineEnd : this._getLineEnd(text, index, model, 1); |
209 |
end = isAtx ? lineEnd : this._getLineEnd(text, index, model, 1); |
|
Lines 541-548
Link Here
|
| 541 |
this._onBlocksChanged({oldBlocks: [], newBlocks: rootBlock.getBlocks()}); |
572 |
this._onBlocksChanged({oldBlocks: [], newBlocks: rootBlock.getBlocks()}); |
| 542 |
}, |
573 |
}, |
| 543 |
/** @callback */ |
574 |
/** @callback */ |
| 544 |
parse: function(text, offset, block, _styles, ignoreCaptures) { |
575 |
parse: function(text, offset, startIndex, block, _styles, ignoreCaptures) { |
| 545 |
if (!block.typeId) { |
576 |
if (!block.typeId) { |
|
|
577 |
return; |
| 578 |
} |
| 579 |
|
| 580 |
/* handle YAML front-matter blocks specially */ |
| 581 |
if (block.typeId === this._YAML_FRONTMATTER) { |
| 582 |
this._yamlStylerAdapter.parse( |
| 583 |
text, |
| 584 |
offset, |
| 585 |
0, |
| 586 |
block, |
| 587 |
_styles |
| 588 |
); |
| 546 |
return; |
589 |
return; |
| 547 |
} |
590 |
} |
| 548 |
|
591 |
|
|
Lines 575-581
Link Here
|
| 575 |
|
618 |
|
| 576 |
var index = 0; |
619 |
var index = 0; |
| 577 |
while (matches.length > 0) { |
620 |
while (matches.length > 0) { |
| 578 |
var current = matches[0]; |
621 |
current = matches[0]; |
| 579 |
matches.splice(0,1); |
622 |
matches.splice(0,1); |
| 580 |
if (current.result.index < index) { |
623 |
if (current.result.index < index) { |
| 581 |
/* processing of another match has moved index beyond this match */ |
624 |
/* processing of another match has moved index beyond this match */ |
|
Lines 792-797
Link Here
|
| 792 |
_generateHTML: function(rootElement, block) { |
835 |
_generateHTML: function(rootElement, block) { |
| 793 |
if (!block.startToken && !block.tokens) { |
836 |
if (!block.startToken && !block.tokens) { |
| 794 |
return; /* likely a block with only tokens for its parent */ |
837 |
return; /* likely a block with only tokens for its parent */ |
|
|
838 |
} |
| 839 |
|
| 840 |
if (block.typeId === this._YAML_FRONTMATTER) { |
| 841 |
rootElement.innerHTML = ""; |
| 842 |
return; |
| 795 |
} |
843 |
} |
| 796 |
|
844 |
|
| 797 |
/* |
845 |
/* |
|
Lines 1229-1234
Link Here
|
| 1229 |
_TYPEID_LISTITEM: "markup.list.item.markdown", //$NON-NLS-0$ |
1277 |
_TYPEID_LISTITEM: "markup.list.item.markdown", //$NON-NLS-0$ |
| 1230 |
_TYPEID_PARAGRAPH: "markup.other.paragraph.markdown", //$NON-NLS-0$ |
1278 |
_TYPEID_PARAGRAPH: "markup.other.paragraph.markdown", //$NON-NLS-0$ |
| 1231 |
_TYPEID_DEF: "meta.link.reference.def.markdown", //$NON-NLS-0$ |
1279 |
_TYPEID_DEF: "meta.link.reference.def.markdown", //$NON-NLS-0$ |
|
|
1280 |
_YAML_FRONTMATTER: "yamlFrontMatter", //$NON-NLS-0$ |
| 1232 |
_atxDetectRegex: /\s*#/g, |
1281 |
_atxDetectRegex: /\s*#/g, |
| 1233 |
_blockquoteRemoveMarkersRegex: /^[ \t]*>[ \t]?/gm, |
1282 |
_blockquoteRemoveMarkersRegex: /^[ \t]*>[ \t]?/gm, |
| 1234 |
_blockquoteStartRegex: /[ \t]*>[ \t]?/g, |
1283 |
_blockquoteStartRegex: /[ \t]*>[ \t]?/g, |
|
Lines 1239-1245
Link Here
|
| 1239 |
_newlineRegex: /\n/g, |
1288 |
_newlineRegex: /\n/g, |
| 1240 |
_orderedListRegex: /\d+\.[ \t]/g, |
1289 |
_orderedListRegex: /\d+\.[ \t]/g, |
| 1241 |
_spacesAndTabsRegex: /[ \t]*/g, |
1290 |
_spacesAndTabsRegex: /[ \t]*/g, |
| 1242 |
_whitespaceRegex: /\s+/g |
1291 |
_whitespaceRegex: /\s+/g, |
|
|
1292 |
_yamlFrontMatterRegex: /^---$/g |
| 1243 |
}; |
1293 |
}; |
| 1244 |
|
1294 |
|
| 1245 |
var _imageCache = {}; |
1295 |
var _imageCache = {}; |
|
Lines 1548-1554
Link Here
|
| 1548 |
var editor = this._editorView.editor; |
1598 |
var editor = this._editorView.editor; |
| 1549 |
var textView = editor.getTextView(); |
1599 |
var textView = editor.getTextView(); |
| 1550 |
var annotationModel = editor.getAnnotationModel(); |
1600 |
var annotationModel = editor.getAnnotationModel(); |
| 1551 |
this._stylerAdapter = new MarkdownStylingAdapter(this._model, this._metadata.Location, this._fileService); |
1601 |
this._stylerAdapter = new MarkdownStylingAdapter(this._model, editor, this._metadata.Location, this._fileService); |
| 1552 |
this._styler = new mTextStyler.TextStyler(textView, annotationModel, this._stylerAdapter); |
1602 |
this._styler = new mTextStyler.TextStyler(textView, annotationModel, this._stylerAdapter); |
| 1553 |
|
1603 |
|
| 1554 |
this._editorView.editor.getTextView().addEventListener("Scroll", this._sourceScrollListener); //$NON-NLS-0$ |
1604 |
this._editorView.editor.getTextView().addEventListener("Scroll", this._sourceScrollListener); //$NON-NLS-0$ |