Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(discussion): auto detect email address #21

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@types/flat": "^5.0.1",
"@types/gravatar": "^1.8.0",
"@types/js-yaml": "^4.0.0",
"@types/linkify-it": "^3.0.2",
"@types/lodash.clonedeep": "^4.5.6",
"@types/lodash.isequal": "^4.5.5",
"@types/lodash.merge": "^4.6.6",
Expand Down Expand Up @@ -76,7 +77,6 @@
"lodash.merge": "^4.6.2",
"markdown-it": "^12.0.4",
"markdown-it-math-loose": "^4.1.1",
"markdown-it-mentions": "^1.0.0",
"markdown-it-merge-cells": "^1.0.1",
"mathjax-full": "^3.1.2",
"mobx": "^4.15.4",
Expand Down
10 changes: 0 additions & 10 deletions patches/markdown-it-mentions+1.0.0.patch

This file was deleted.

23 changes: 19 additions & 4 deletions src/markdown/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { v4 as uuid } from "uuid";

import MarkdownItMath from "markdown-it-math-loose";
import MarkdownItMergeCells from "markdown-it-merge-cells/src";
import MarkdownItMentions from "markdown-it-mentions";
import MarkdownItTaskLists from "@hackmd/markdown-it-task-lists";
import LinkifyIt from "linkify-it";

export interface MarkdownHighlightPlaceholder {
id: string;
Expand Down Expand Up @@ -84,13 +84,28 @@ export function renderMarkdown(
blockRenderer: (code: string) => addMathPlaceholder(code, true)
});
renderer.use(MarkdownItMergeCells);
renderer.use(MarkdownItMentions, {
parseURL: (username: string) => `/u/${username}`
renbaoshuo marked this conversation as resolved.
Show resolved Hide resolved
});
renderer.use(MarkdownItTaskLists, {
enabled: true
});

renderer.linkify.add("@", {
validate: (text: string, pos: number, self: LinkifyIt.LinkifyIt): number | boolean => {
var tail: string = text.slice(pos);
const re: RegExp = /^[a-zA-Z0-9\-_.#$]{3,24}$/;

if (re.test(tail)) {
if (pos >= 2 && tail[pos - 2] === "@") {
return false;
}
return tail.match(re)[0].length;
}
return 0;
},
normalize: (match: LinkifyIt.Match): void => {
match.url = "/u/" + match.url.replace(/^@/, "");
}
});

if (onPatchRenderer) onPatchRenderer(renderer);

return [renderer.render(text), highlightPlaceholders, mathPlaceholders, findPlaceholderElement];
Expand Down
17 changes: 5 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,11 @@
resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-2.1.0.tgz#ea3dd64c4805597311790b61e872cbd1ed2cd806"
integrity sha512-Q7DYAOi9O/+cLLhdaSvKdaumWyHbm7HAk/bFwwyTuU0arR5yyCeW5GOoqt4tJTpDRxhpx9Q8kQL6vMpuw9hDSw==

"@types/linkify-it@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.2.tgz#fd2cd2edbaa7eaac7e7f3c1748b52a19143846c9"
integrity sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==

"@types/lodash.clonedeep@^4.5.6":
version "4.5.6"
resolved "https://registry.yarnpkg.com/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.6.tgz#3b6c40a0affe0799a2ce823b440a6cf33571d32b"
Expand Down Expand Up @@ -8794,25 +8799,13 @@ markdown-it-math-loose@^4.1.1:
optionalDependencies:
ascii2mathml "^0.6.2"

markdown-it-mentions@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-mentions/-/markdown-it-mentions-1.0.0.tgz#2dc6a06d0604bfbf57ac22efb3558f338098990a"
integrity sha512-zZnkEWHfnIXCwzgv9WJh0Wo6iuwLJaApfOMQfKEqjYM5A98XXEChPRqI7jvZAdzPGfCfaBFv0GUQqUYw4DeSjg==
dependencies:
markdown-it-regexp "^0.4.0"

markdown-it-merge-cells@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/markdown-it-merge-cells/-/markdown-it-merge-cells-1.0.1.tgz#ad375a09fa709213c19a354e537e560789ae2be8"
integrity sha512-4I6wBy8OPgPRSYAw7VC3SEgIcuM7HiFvTi1AW9bbPYRoXoAsr6inyjX723gyDUUj9dQT7ICNWtxrom9ULOW46A==
dependencies:
babel-runtime "^6.26.0"

markdown-it-regexp@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/markdown-it-regexp/-/markdown-it-regexp-0.4.0.tgz#d64d713eecec55ce4cfdeb321750ecc099e2c2dc"
integrity sha1-1k1xPuzsVc5M/esyF1DswJniwtw=

markdown-it@^12.0.4:
version "12.0.4"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-12.0.4.tgz#eec8247d296327eac3ba9746bdeec9cfcc751e33"
Expand Down