diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parse/lex.js | 11 | ||||
-rw-r--r-- | lib/parse/page.js | 7 |
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/parse/lex.js b/lib/parse/lex.js index 941e537..6b3236e 100644 --- a/lib/parse/lex.js +++ b/lib/parse/lex.js @@ -30,6 +30,11 @@ function sectionType(nodes, idx) { return 'normal'; } +// Generate a uniqueId to identify this section in our code +function sectionId(section, idx) { + return _.uniqueId('gitbook_'); +} + function lexPage(src) { // Lex file var nodes = marked.lexer(src); @@ -40,6 +45,12 @@ function lexPage(src) { section.type = sectionType(section, idx); return section; }) + .map(function(section, idx) { + // Give each section an ID + section.id = sectionId(section, idx); + return section; + + }) .filter(function(section) { return !_.isEmpty(section); }) diff --git a/lib/parse/page.js b/lib/parse/page.js index 559be91..56a9e60 100644 --- a/lib/parse/page.js +++ b/lib/parse/page.js @@ -42,9 +42,6 @@ function parsePage(src, options) { // Lex if not already lexed return (_.isArray(src) ? src : lex(src)) .map(function(section) { - // Generate a uniqueId to identify this section in our code - var id = _.uniqueId('gitbook_'); - // Transform given type if(section.type === 'exercise') { var nonCodeNodes = _.reject(section, { @@ -67,7 +64,7 @@ function parsePage(src, options) { var lang = validLangs ? langs[0] : null; return { - id: id, + id: section.id, type: section.type, content: render(nonCodeNodes), lang: lang, @@ -81,7 +78,7 @@ function parsePage(src, options) { // Render normal pages return { - id: id, + id: section.id, type: section.type, content: render(section, options) }; |