summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-markdown')
-rw-r--r--packages/gitbook-markdown/lib/annotate.js10
-rw-r--r--packages/gitbook-markdown/lib/annotate_blocks.js46
-rw-r--r--packages/gitbook-markdown/lib/annotate_engine.js43
-rw-r--r--packages/gitbook-markdown/lib/annotate_inline.js41
-rw-r--r--packages/gitbook-markdown/lib/page.js13
5 files changed, 8 insertions, 145 deletions
diff --git a/packages/gitbook-markdown/lib/annotate.js b/packages/gitbook-markdown/lib/annotate.js
deleted file mode 100644
index 8cc7f89..0000000
--- a/packages/gitbook-markdown/lib/annotate.js
+++ /dev/null
@@ -1,10 +0,0 @@
-var blocks = require('./annotate_blocks');
-var inline = require('./annotate_inline');
-
-function annotate(src) {
- return blocks(src);
-}
-
-module.exports = annotate;
-module.exports.blocks = blocks;
-module.exports.inline = inline;
diff --git a/packages/gitbook-markdown/lib/annotate_blocks.js b/packages/gitbook-markdown/lib/annotate_blocks.js
deleted file mode 100644
index a609083..0000000
--- a/packages/gitbook-markdown/lib/annotate_blocks.js
+++ /dev/null
@@ -1,46 +0,0 @@
-var engine = require('./annotate_engine');
-
-// Pulled from "kramed.Lexer.rules.tables"
-var rules = { newline: /^\n+/,
- code: /^( {4}|\t[^\n]+\n*)+/,
- fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n|$)/,
- hr: /^( *[-*_]){3,} *(?:\n|$)/,
- heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n|$)/,
- nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
- lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n|$)/,
- blockquote: /^( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n|$))[^\n]+)*\n*)+/,
- list: /^( *)((?:[*+-]|\d+\.)) [\s\S]+?(?:\n+(?=\1?(?:[-*_] *){3,}(?:\n|$))|\n+(?= *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n|$))|\n{2,}(?! )(?!\1(?:[*+-]|\d+\.) )\n*|\s*$)/,
- html: /^ *(?:<!--[\s\S]*?--> *(?:\n|\s*$)|<((?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b)[\s\S]+?<\/\1> *(?:\n{2,}|\s*$)|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b(?:"[^"]*"|'[^']*'|[^'">])*?> *(?:\n{2,}|\s*$))/,
- def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n|$)/,
- footnote: /^\[\^([^\]]+)\]: ([^\n]+)/,
- table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/,
- paragraph: /^((?:[^\n]+\n?(?! *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\2 *(?:\n|$)|( *)((?:[*+-]|\d+\.)) [\s\S]+?(?:\n+(?=\3?(?:[-*_] *){3,}(?:\n|$))|\n+(?= *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n|$))|\n{2,}(?! )(?!\1(?:[*+-]|\d+\.) )\n*|\s*$)|( *[-*_]){3,} *(?:\n|$)| *(#{1,6}) *([^\n]+?) *#* *(?:\n|$)|([^\n]+)\n *(=|-){2,} *(?:\n|$)|( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n|$))[^\n]+)*\n*)+|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b| *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n|$)| *(\${2,}) *([\s\S]+?)\s*\1 *(?:\n|$)))+)\n*/,
- text: /^[^\n]+/,
- //rawStart: /^{%([\s]*)raw([\s]*)%}/,
- //rawEnd: /^{%([\s]*)endraw([\s]*)%}/
- // These are lower level, ignore them
- //bullet: /(?:[*+-]|\d+\.)/,
- //item: /^( *)((?:[*+-]|\d+\.)) [^\n]*(?:\n(?!\1(?:[*+-]|\d+\.) )[^\n]*)*/gm,
- //_tag: '(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b'
-};
-
-// List of all the regexes we want to run
-var ruleTypes = [
- 'newline', 'code', 'fences', 'footnote', 'heading',
- 'nptable', 'lheading', 'hr', 'blockquote', 'list',
- 'html', 'def', 'table', 'paragraph', 'text',
-];
-
-// Mapping if rule type is different from token type
-var ruleMap = {
- 'nptable': 'table',
- 'lheading': 'heading',
- 'newline': 'space',
- 'fences': 'code',
-};
-
-function annotate(src) {
- return engine(src, rules, ruleTypes, ruleMap);
-}
-
-module.exports = annotate;
diff --git a/packages/gitbook-markdown/lib/annotate_engine.js b/packages/gitbook-markdown/lib/annotate_engine.js
deleted file mode 100644
index 181ee30..0000000
--- a/packages/gitbook-markdown/lib/annotate_engine.js
+++ /dev/null
@@ -1,43 +0,0 @@
-function annotateEngine(src, rules, ruleTypes, ruleMap) {
- var tokens = [];
-
- while(src) {
- // Pick rule
- var rule = ruleTypes.filter(function(ruleName, idx) {
- var regex = rules[ruleName];
- return regex.exec(src);
- })[0];
-
- // No matching rules
- if(!rule) {
- throw new Error('No rule found for: ' + src);
- }
-
- // Use rule to extract block
- var ruleRegex = rules[rule];
- var block = ruleRegex.exec(src);
-
- // Get rule type
- var type = ruleMap[rule] || rule;
-
- // Get raw text
- var raw = block[0];
-
- // Break out here to avoid infinite loops
- if(raw.length === 0) {
- break;
- }
-
- tokens.push({
- type: ruleMap[rule] || rule,
- raw: raw,
- });
-
- // Update source
- src = src.substring(raw.length);
- }
-
- return tokens;
-}
-
-module.exports = annotateEngine;
diff --git a/packages/gitbook-markdown/lib/annotate_inline.js b/packages/gitbook-markdown/lib/annotate_inline.js
deleted file mode 100644
index 469f4d8..0000000
--- a/packages/gitbook-markdown/lib/annotate_inline.js
+++ /dev/null
@@ -1,41 +0,0 @@
-var engine = require('./annotate_engine');
-
-// Pulled from "kramed.InlineLexer.rules.gfm"
-var rules = {
- escape: /^\\([\\`*{}\[\]()#$+\-.!_>~|])/,
- autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
- url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
- tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
- link: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\(\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*\)/,
- reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\s*\[([^\]]*)\]/,
- nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
- reffn: /^!?\[\^((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]/,
- strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
- em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
- code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
- br: /^ {2,}\n(?!\s*$)/,
- del: /^~~(?=\S)([\s\S]*?\S)~~/,
- text: /^[\s\S]+?(?=[\\<!\[_*`$~]|{%([\s]*)raw([\s]*)%}|{%([\s]*)endraw([\s]*)|https?:\/\/| {2,}\n|$)/,
- rawStart: /^{%([\s]*)raw([\s]*)%}/,
- rawEnd: /^{%([\s]*)endraw([\s]*)%}/ ///[\s\S]*{%([\s]*)endraw([\s]*)%}/
- //_inside: /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/,
- //_href: /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/
-};
-
-// List of all the regexes we want to run
-var ruleTypes = [
- 'escape', 'autolink', 'url', 'tag', 'link', 'reflink',
- 'nolink', 'reffn', 'strong', 'em', 'code', 'br',
- 'del', 'rawStart', 'rawEnd', 'text'
-];
-
-// Mapping if rule type is different from token type
-var ruleMap = {
-
-};
-
-function annotate(src) {
- return engine(src, rules, ruleTypes, ruleMap);
-}
-
-module.exports = annotate;
diff --git a/packages/gitbook-markdown/lib/page.js b/packages/gitbook-markdown/lib/page.js
index 246c71d..6f1f86b 100644
--- a/packages/gitbook-markdown/lib/page.js
+++ b/packages/gitbook-markdown/lib/page.js
@@ -1,7 +1,7 @@
var _ = require('lodash');
var kramed = require('kramed');
-var annotate = require('./annotate');
+var annotate = require('kramed/lib/annotate/');
var RAW_START = "{% raw %}";
var RAW_END = "{% endraw %}";
@@ -22,10 +22,13 @@ function preparePage(src) {
var escapeCodeElement = function(el) {
if (el.type == 'code' && levelRaw == 0) {
el.raw = escape(el.raw);
- } else if (el.type == 'rawStart') {
- levelRaw = levelRaw + 1;
- } else if (el.type == 'rawEnd') {
- levelRaw = 0;
+ } else if (el.type == 'tplexpr') {
+ var expr = el.matches[0];
+ if(expr === 'raw') {
+ levelRaw = levelRaw + 1;
+ } else if(expr === 'endraw') {
+ levelRaw = 0;
+ }
}
return el;
};