mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
web: replace marked with snarkdown
This commit is contained in:
committed by
Abdullah Atta
parent
60aa92ca03
commit
d0dcdcd337
@@ -61,7 +61,6 @@
|
|||||||
"hotkeys-js": "^3.8.3",
|
"hotkeys-js": "^3.8.3",
|
||||||
"katex": "0.16.2",
|
"katex": "0.16.2",
|
||||||
"mac-scrollbar": "^0.13.5",
|
"mac-scrollbar": "^0.13.5",
|
||||||
"marked": "^4.1.0",
|
|
||||||
"mutative": "^1.0.6",
|
"mutative": "^1.0.6",
|
||||||
"pdfjs-dist": "3.6.172",
|
"pdfjs-dist": "3.6.172",
|
||||||
"phone": "^3.1.14",
|
"phone": "^3.1.14",
|
||||||
@@ -82,6 +81,7 @@
|
|||||||
"react-resizable-panels": "^2.0.17",
|
"react-resizable-panels": "^2.0.17",
|
||||||
"react-scroll-sync": "^0.11.2",
|
"react-scroll-sync": "^0.11.2",
|
||||||
"react-virtuoso": "^4.6.2",
|
"react-virtuoso": "^4.6.2",
|
||||||
|
"snarkdown": "^2.0.0",
|
||||||
"timeago.js": "4.0.2",
|
"timeago.js": "4.0.2",
|
||||||
"tinycolor2": "^1.6.0",
|
"tinycolor2": "^1.6.0",
|
||||||
"w3c-keyname": "^2.2.6",
|
"w3c-keyname": "^2.2.6",
|
||||||
|
|||||||
@@ -17,38 +17,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { marked } from "marked";
|
import snarkdown from "snarkdown";
|
||||||
|
|
||||||
const emoji: marked.TokenizerExtension & marked.RendererExtension = {
|
|
||||||
name: "emoji",
|
|
||||||
level: "inline",
|
|
||||||
start(src) {
|
|
||||||
return src.indexOf(":");
|
|
||||||
},
|
|
||||||
tokenizer(src, _tokens) {
|
|
||||||
const rule = /^:(\w+):/;
|
|
||||||
const match = rule.exec(src);
|
|
||||||
if (match) {
|
|
||||||
return {
|
|
||||||
type: "emoji",
|
|
||||||
raw: match[0],
|
|
||||||
emoji: match[1]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
renderer(token) {
|
|
||||||
return `<span className="emoji ${token}" />`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderer = new marked.Renderer();
|
|
||||||
renderer.link = function (href, title, text) {
|
|
||||||
return `<a target="_blank" rel="noopener noreferrer" href="${href}" ${
|
|
||||||
title ? `title=${title}` : ""
|
|
||||||
}>${text}</a>`;
|
|
||||||
};
|
|
||||||
marked.use({ extensions: [emoji] });
|
|
||||||
|
|
||||||
export function mdToHtml(markdown: string) {
|
export function mdToHtml(markdown: string) {
|
||||||
return marked.parse(markdown, { async: false, renderer, gfm: true });
|
return snarkdown(markdown);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user