tiptap-markdown
Advanced tools
Comparing version 0.8.6 to 0.8.7
{ | ||
"name": "tiptap-markdown", | ||
"version": "0.8.6", | ||
"version": "0.8.7", | ||
"description": "Edit markdown content in tiptap editor.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
import markdownit from "markdown-it"; | ||
import { elementFromString, extractElement, unwrapElement } from "../util/dom"; | ||
import { getMarkdownSpec } from "../util/extensions"; | ||
import { Renderer } from "./Renderer.js"; | ||
@@ -15,15 +14,10 @@ export class MarkdownParser { | ||
md = null; | ||
/** | ||
* @type {Renderer} | ||
*/ | ||
renderer = null; | ||
constructor(editor, { html, linkify, breaks }) { | ||
this.editor = editor; | ||
this.md = markdownit({ | ||
this.md = this.withPatchedRenderer(markdownit({ | ||
html, | ||
linkify, | ||
breaks, | ||
}); | ||
this.renderer = new Renderer(); | ||
})); | ||
} | ||
@@ -37,3 +31,3 @@ | ||
const renderedHTML = this.renderer.render(this.md.parse(content, {}), this.md.options, {}); | ||
const renderedHTML = this.md.render(content); | ||
const element = elementFromString(renderedHTML); | ||
@@ -110,3 +104,27 @@ | ||
} | ||
/** | ||
* @param {markdownit} md | ||
*/ | ||
withPatchedRenderer(md) { | ||
const withoutNewLine = (renderer) => (...args) => { | ||
const rendered = renderer(...args); | ||
if(rendered === '\n') { | ||
return rendered; // keep soft breaks | ||
} | ||
if(rendered[rendered.length - 1] === '\n') { | ||
return rendered.slice(0, -1); | ||
} | ||
return rendered; | ||
} | ||
md.renderer.rules.hardbreak = withoutNewLine(md.renderer.rules.hardbreak); | ||
md.renderer.rules.softbreak = withoutNewLine(md.renderer.rules.softbreak); | ||
md.renderer.rules.fence = withoutNewLine(md.renderer.rules.fence); | ||
md.renderer.rules.code_block = withoutNewLine(md.renderer.rules.code_block); | ||
md.renderer.renderToken = withoutNewLine(md.renderer.renderToken.bind(md.renderer)); | ||
return md; | ||
} | ||
} | ||
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 too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
231527
41
3110