markmap-lib
Advanced tools
Comparing version 0.16.1 to 0.16.3-alpha.2
@@ -5,7 +5,19 @@ "use strict"; | ||
const markmapHtmlParser = require("markmap-html-parser"); | ||
const remarkable = require("remarkable"); | ||
const MarkdownIt = require("markdown-it"); | ||
const md_ins = require("markdown-it-ins"); | ||
const md_mark = require("markdown-it-mark"); | ||
const md_sub = require("markdown-it-sub"); | ||
const md_sup = require("markdown-it-sup"); | ||
const plugins = require("./plugins.js"); | ||
require("js-yaml"); | ||
require("highlight.js"); | ||
require("remarkable-katex"); | ||
require("@iktakahiro/markdown-it-katex"); | ||
function initializeMarkdownIt() { | ||
const md = MarkdownIt({ | ||
html: true, | ||
breaks: true | ||
}); | ||
md.use(md_ins).use(md_mark).use(md_sub).use(md_sup); | ||
return md; | ||
} | ||
function patchJSItem(urlBuilder, item) { | ||
@@ -64,15 +76,3 @@ if (item.type === "script" && item.data.src) { | ||
this.assetsMap = assetsMap; | ||
const md = new remarkable.Remarkable("full", { | ||
html: true, | ||
breaks: true, | ||
maxNesting: Infinity | ||
}); | ||
md.renderer.rules.htmltag = markmapCommon.wrapFunction( | ||
md.renderer.rules.htmltag, | ||
(render, ...args) => { | ||
const result = render(...args); | ||
this.hooks.htmltag.call({ args, result }); | ||
return result; | ||
} | ||
); | ||
const md = initializeMarkdownIt(); | ||
this.md = md; | ||
@@ -82,3 +82,3 @@ this.hooks.parser.call(md); | ||
transform(content, opts) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
const context = { | ||
@@ -98,2 +98,3 @@ content, | ||
); | ||
root.content || (root.content = `${((_c = context.frontmatter) == null ? void 0 : _c.title) || ""}`); | ||
return { ...context, root }; | ||
@@ -130,3 +131,3 @@ } | ||
const transformerVersions = { | ||
"markmap-lib": "0.16.1" | ||
"markmap-lib": "0.16.3-alpha.2+0f4c3f8" | ||
}; | ||
@@ -133,0 +134,0 @@ exports.Transformer = Transformer; |
@@ -5,3 +5,15 @@ "use strict"; | ||
const markmapHtmlParser = require("markmap-html-parser"); | ||
const remarkable = require("remarkable"); | ||
const MarkdownIt = require("markdown-it"); | ||
const md_ins = require("markdown-it-ins"); | ||
const md_mark = require("markdown-it-mark"); | ||
const md_sub = require("markdown-it-sub"); | ||
const md_sup = require("markdown-it-sup"); | ||
function initializeMarkdownIt() { | ||
const md = MarkdownIt({ | ||
html: true, | ||
breaks: true | ||
}); | ||
md.use(md_ins).use(md_mark).use(md_sub).use(md_sup); | ||
return md; | ||
} | ||
function createTransformHooks(transformer) { | ||
@@ -13,3 +25,2 @@ return { | ||
afterParse: new markmapCommon.Hook(), | ||
htmltag: new markmapCommon.Hook(), | ||
retransform: new markmapCommon.Hook() | ||
@@ -71,15 +82,3 @@ }; | ||
this.assetsMap = assetsMap; | ||
const md = new remarkable.Remarkable("full", { | ||
html: true, | ||
breaks: true, | ||
maxNesting: Infinity | ||
}); | ||
md.renderer.rules.htmltag = markmapCommon.wrapFunction( | ||
md.renderer.rules.htmltag, | ||
(render, ...args) => { | ||
const result = render(...args); | ||
this.hooks.htmltag.call({ args, result }); | ||
return result; | ||
} | ||
); | ||
const md = initializeMarkdownIt(); | ||
this.md = md; | ||
@@ -89,3 +88,3 @@ this.hooks.parser.call(md); | ||
transform(content, opts) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
const context = { | ||
@@ -105,2 +104,3 @@ content, | ||
); | ||
root.content || (root.content = `${((_c = context.frontmatter) == null ? void 0 : _c.title) || ""}`); | ||
return { ...context, root }; | ||
@@ -137,3 +137,3 @@ } | ||
const transformerVersions = { | ||
"markmap-lib": "0.16.1" | ||
"markmap-lib": "0.16.3-alpha.2+0f4c3f8" | ||
}; | ||
@@ -140,0 +140,0 @@ exports.Transformer = Transformer; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const hljs = require("highlight.js"); | ||
const remarkableKatex = require("remarkable-katex"); | ||
const katexPlugin = require("@iktakahiro/markdown-it-katex"); | ||
function createTransformHooks(transformer) { | ||
@@ -14,3 +14,2 @@ return { | ||
afterParse: new markmapCommon.Hook(), | ||
htmltag: new markmapCommon.Hook(), | ||
retransform: new markmapCommon.Hook() | ||
@@ -33,23 +32,18 @@ }; | ||
transformHooks.parser.tap((md) => { | ||
md.core.ruler.before( | ||
"inline", | ||
"checkbox", | ||
(state) => { | ||
for (let i = 2; i < state.tokens.length; i += 1) { | ||
const token = state.tokens[i]; | ||
if (token.type === "inline" && token.content) { | ||
const prevType = state.tokens[i - 1].type; | ||
const prevPrevType = state.tokens[i - 2].type; | ||
if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") { | ||
token.content = token.content.replace( | ||
/^\[(.)\] /, | ||
(m, g) => images[g] ? `${images[g]} ` : m | ||
); | ||
} | ||
md.core.ruler.before("inline", "checkbox", (state) => { | ||
for (let i = 2; i < state.tokens.length; i += 1) { | ||
const token = state.tokens[i]; | ||
if (token.type === "inline" && token.content) { | ||
const prevType = state.tokens[i - 1].type; | ||
const prevPrevType = state.tokens[i - 2].type; | ||
if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") { | ||
token.content = token.content.replace( | ||
/^\[(.)\] /, | ||
(m, g) => images[g] ? `${images[g]} ` : m | ||
); | ||
} | ||
} | ||
return false; | ||
}, | ||
{} | ||
); | ||
} | ||
return false; | ||
}); | ||
}); | ||
@@ -215,10 +209,12 @@ return {}; | ||
transformHooks.parser.tap((md) => { | ||
md.use(remarkableKatex); | ||
md.renderer.rules.katex = markmapCommon.wrapFunction( | ||
md.renderer.rules.katex, | ||
(render, ...args) => { | ||
enableFeature(); | ||
return render(...args); | ||
md.use(katexPlugin); | ||
["math_block", "math_inline"].forEach((key) => { | ||
const fn = md.renderer.rules[key]; | ||
if (fn) { | ||
md.renderer.rules[key] = markmapCommon.wrapFunction(fn, (render, ...args) => { | ||
enableFeature(); | ||
return render(...args); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -268,11 +264,12 @@ transformHooks.beforeParse.tap((_, context) => { | ||
transformHooks.parser.tap((md) => { | ||
Object.entries(md.renderer.rules).forEach(([key, value]) => { | ||
if (typeof value === "function") { | ||
md.renderer.rules[key] = patchRule(value); | ||
} else { | ||
Object.entries(value).forEach(([k, v]) => { | ||
value[k] = patchRule(v); | ||
}); | ||
md.renderer.renderAttrs = markmapCommon.wrapFunction( | ||
md.renderer.renderAttrs, | ||
(renderAttrs, token) => { | ||
let attrs = renderAttrs(token); | ||
if (token.block && token.map) { | ||
attrs += ` data-lines=${token.map.join(",")}`; | ||
} | ||
return attrs; | ||
} | ||
}); | ||
); | ||
}); | ||
@@ -282,15 +279,2 @@ return {}; | ||
}); | ||
function patchRule(rule, _key) { | ||
return markmapCommon.wrapFunction(rule, (render, tokens, idx, ...rest) => { | ||
let html = render(tokens, idx, ...rest); | ||
const { lines } = tokens[idx]; | ||
if (lines) { | ||
html = html.replace( | ||
/^<[\w-]+/, | ||
(m) => `${m} data-lines="${lines.join(",")}"` | ||
); | ||
} | ||
return html; | ||
}); | ||
} | ||
const pluginSourceLines = plugin; | ||
@@ -297,0 +281,0 @@ const plugins = [ |
@@ -0,4 +1,4 @@ | ||
import type MarkdownIt from 'markdown-it'; | ||
import { UrlBuilder } from 'markmap-common'; | ||
import { IHtmlParserOptions } from 'markmap-html-parser'; | ||
import { Remarkable } from 'remarkable'; | ||
import { IAssets, IFeatures, ITransformHooks, ITransformPlugin, ITransformResult, ITransformer } from './types'; | ||
@@ -8,3 +8,3 @@ export declare const builtInPlugins: ITransformPlugin[]; | ||
hooks: ITransformHooks; | ||
md: Remarkable; | ||
md: MarkdownIt; | ||
assetsMap: Record<string, IAssets>; | ||
@@ -11,0 +11,0 @@ urlBuilder: UrlBuilder; |
@@ -1,6 +0,5 @@ | ||
import { CSSItem, Hook, IPureNode, IWrapContext, JSItem, UrlBuilder } from 'markmap-common'; | ||
import type MarkdownIt from 'markdown-it'; | ||
import { CSSItem, Hook, IPureNode, JSItem, UrlBuilder } from 'markmap-common'; | ||
import { IHtmlParserOptions } from 'markmap-html-parser'; | ||
import { IMarkmapJSONOptions as IMarkmapJSONOptionsForView } from 'markmap-view'; | ||
import type { Remarkable } from 'remarkable'; | ||
type Htmltag = Remarkable.Rule<Remarkable.HtmlTagToken, string>; | ||
export interface ITransformHooks { | ||
@@ -11,16 +10,12 @@ transformer: ITransformer; | ||
*/ | ||
parser: Hook<[md: Remarkable]>; | ||
parser: Hook<[md: MarkdownIt]>; | ||
/** | ||
* Tapped every time before Markdown content is parsed. | ||
*/ | ||
beforeParse: Hook<[md: Remarkable, context: ITransformContext]>; | ||
beforeParse: Hook<[md: MarkdownIt, context: ITransformContext]>; | ||
/** | ||
* Tapped every time after Markdown content is parsed. | ||
*/ | ||
afterParse: Hook<[md: Remarkable, context: ITransformContext]>; | ||
afterParse: Hook<[md: MarkdownIt, context: ITransformContext]>; | ||
/** | ||
* Tapped when Remarkable renders an HTML tag in Markdown. | ||
*/ | ||
htmltag: Hook<[ctx: IWrapContext<Parameters<Htmltag>, ReturnType<Htmltag>>]>; | ||
/** | ||
* Used in autoloader to force rerender when resource is loaded. | ||
@@ -58,2 +53,3 @@ */ | ||
frontmatter?: { | ||
title?: string; | ||
markmap?: IMarkmapJSONOptions; | ||
@@ -78,2 +74,1 @@ }; | ||
} | ||
export {}; |
{ | ||
"name": "markmap-lib", | ||
"version": "0.16.1", | ||
"version": "0.16.3-alpha.2+0f4c3f8", | ||
"description": "Visualize your Markdown as mindmaps with Markmap", | ||
@@ -61,3 +61,4 @@ "author": "Gerald <gera2ld@live.com>", | ||
"@highlightjs/cdn-assets": "^11.8.0", | ||
"@types/remarkable": "^2.0.3", | ||
"@types/katex": "^0.16.7", | ||
"@types/markdown-it": "^14.0.0", | ||
"markmap-common": "0.16.0", | ||
@@ -68,10 +69,14 @@ "webfontloader": "^1.6.28" | ||
"@babel/runtime": "^7.22.6", | ||
"@iktakahiro/markdown-it-katex": "^4.0.1", | ||
"highlight.js": "^11.8.0", | ||
"js-yaml": "^4.1.0", | ||
"katex": "^0.16.8", | ||
"markdown-it": "^14.1.0", | ||
"markdown-it-ins": "^4.0.0", | ||
"markdown-it-mark": "^4.0.0", | ||
"markdown-it-sub": "^2.0.0", | ||
"markdown-it-sup": "^2.0.0", | ||
"markmap-html-parser": "0.16.1", | ||
"markmap-view": "0.16.0", | ||
"prismjs": "^1.29.0", | ||
"remarkable": "^2.0.1", | ||
"remarkable-katex": "^1.2.1" | ||
"markmap-view": "0.16.3-alpha.2+0f4c3f8", | ||
"prismjs": "^1.29.0" | ||
}, | ||
@@ -95,3 +100,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "f10ad62ef03e02a1843484cca51521f48989fab7" | ||
"gitHead": "0f4c3f84ff21f0957ec3dbf338ed7a453f050638" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
832245
32
24465
14
5
2
+ Addedmarkdown-it@^14.1.0
+ Addedmarkdown-it-ins@^4.0.0
+ Addedmarkdown-it-mark@^4.0.0
+ Addedmarkdown-it-sub@^2.0.0
+ Addedmarkdown-it-sup@^2.0.0
+ Added@iktakahiro/markdown-it-katex@4.0.1(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedkatex@0.12.0(transitive)
+ Addedlinkify-it@5.0.0(transitive)
+ Addedmarkdown-it@14.1.0(transitive)
+ Addedmarkdown-it-ins@4.0.0(transitive)
+ Addedmarkdown-it-mark@4.0.0(transitive)
+ Addedmarkdown-it-sub@2.0.0(transitive)
+ Addedmarkdown-it-sup@2.0.0(transitive)
+ Addedmdurl@2.0.0(transitive)
+ Addedpunycode.js@2.3.1(transitive)
+ Addeduc.micro@2.1.0(transitive)
- Removedremarkable@^2.0.1
- Removedremarkable-katex@^1.2.1
- Removed@types/d3@7.4.3(transitive)
- Removed@types/d3-array@3.2.1(transitive)
- Removed@types/d3-axis@3.0.6(transitive)
- Removed@types/d3-brush@3.0.6(transitive)
- Removed@types/d3-chord@3.0.6(transitive)
- Removed@types/d3-color@3.1.3(transitive)
- Removed@types/d3-contour@3.0.6(transitive)
- Removed@types/d3-delaunay@6.0.4(transitive)
- Removed@types/d3-dispatch@3.0.6(transitive)
- Removed@types/d3-drag@3.0.7(transitive)
- Removed@types/d3-dsv@3.0.7(transitive)
- Removed@types/d3-ease@3.0.2(transitive)
- Removed@types/d3-fetch@3.0.7(transitive)
- Removed@types/d3-force@3.0.10(transitive)
- Removed@types/d3-format@3.0.4(transitive)
- Removed@types/d3-geo@3.1.0(transitive)
- Removed@types/d3-hierarchy@3.1.7(transitive)
- Removed@types/d3-interpolate@3.0.4(transitive)
- Removed@types/d3-path@3.1.0(transitive)
- Removed@types/d3-polygon@3.0.2(transitive)
- Removed@types/d3-quadtree@3.0.6(transitive)
- Removed@types/d3-random@3.0.3(transitive)
- Removed@types/d3-scale@4.0.8(transitive)
- Removed@types/d3-scale-chromatic@3.1.0(transitive)
- Removed@types/d3-selection@3.0.11(transitive)
- Removed@types/d3-shape@3.1.7(transitive)
- Removed@types/d3-time@3.0.4(transitive)
- Removed@types/d3-time-format@4.0.3(transitive)
- Removed@types/d3-timer@3.0.2(transitive)
- Removed@types/d3-transition@3.0.9(transitive)
- Removed@types/d3-zoom@3.0.8(transitive)
- Removed@types/geojson@7946.0.16(transitive)
- Removedargparse@1.0.10(transitive)
- Removedautolinker@3.16.2(transitive)
- Removedcommander@7.2.0(transitive)
- Removedd3@7.9.0(transitive)
- Removedd3-array@3.2.4(transitive)
- Removedd3-axis@3.0.0(transitive)
- Removedd3-brush@3.0.0(transitive)
- Removedd3-chord@3.0.1(transitive)
- Removedd3-color@3.1.0(transitive)
- Removedd3-contour@4.0.2(transitive)
- Removedd3-delaunay@6.0.4(transitive)
- Removedd3-dispatch@3.0.1(transitive)
- Removedd3-drag@3.0.0(transitive)
- Removedd3-dsv@3.0.1(transitive)
- Removedd3-ease@3.0.1(transitive)
- Removedd3-fetch@3.0.1(transitive)
- Removedd3-flextree@2.1.2(transitive)
- Removedd3-force@3.0.0(transitive)
- Removedd3-format@3.1.0(transitive)
- Removedd3-geo@3.1.1(transitive)
- Removedd3-hierarchy@1.1.93.1.2(transitive)
- Removedd3-interpolate@3.0.1(transitive)
- Removedd3-path@3.1.0(transitive)
- Removedd3-polygon@3.0.1(transitive)
- Removedd3-quadtree@3.0.1(transitive)
- Removedd3-random@3.0.1(transitive)
- Removedd3-scale@4.0.2(transitive)
- Removedd3-scale-chromatic@3.1.0(transitive)
- Removedd3-selection@3.0.0(transitive)
- Removedd3-shape@3.2.0(transitive)
- Removedd3-time@3.1.0(transitive)
- Removedd3-time-format@4.1.0(transitive)
- Removedd3-timer@3.0.1(transitive)
- Removedd3-transition@3.0.1(transitive)
- Removedd3-zoom@3.0.0(transitive)
- Removeddelaunator@5.0.1(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedinternmap@2.0.3(transitive)
- Removedmarkmap-view@0.16.0(transitive)
- Removedremarkable@2.0.1(transitive)
- Removedremarkable-katex@1.2.1(transitive)
- Removedrobust-predicates@3.0.2(transitive)
- Removedrw@1.3.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedtslib@2.8.1(transitive)