FEATURE: support `mark` tag (#12088)
This commit adds support for `mark` tag for highlighting text content.
This commit is contained in:
parent
4b05fc2d2d
commit
85c4e8fd32
|
@ -113,7 +113,18 @@ export class Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
static allowedTags() {
|
static allowedTags() {
|
||||||
return ["ins", "del", "small", "big", "kbd", "ruby", "rt", "rb", "rp"];
|
return [
|
||||||
|
"ins",
|
||||||
|
"del",
|
||||||
|
"small",
|
||||||
|
"big",
|
||||||
|
"kbd",
|
||||||
|
"ruby",
|
||||||
|
"rt",
|
||||||
|
"rb",
|
||||||
|
"rp",
|
||||||
|
"mark",
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static block(name, prefix, suffix) {
|
static block(name, prefix, suffix) {
|
||||||
|
|
|
@ -71,7 +71,6 @@ module("Unit | Utility | sanitizer", function () {
|
||||||
assert.equal(pt.sanitize("<button>press me!</button>"), "press me!");
|
assert.equal(pt.sanitize("<button>press me!</button>"), "press me!");
|
||||||
assert.equal(pt.sanitize("<canvas>draw me!</canvas>"), "draw me!");
|
assert.equal(pt.sanitize("<canvas>draw me!</canvas>"), "draw me!");
|
||||||
assert.equal(pt.sanitize("<progress>hello"), "hello");
|
assert.equal(pt.sanitize("<progress>hello"), "hello");
|
||||||
assert.equal(pt.sanitize("<mark>highlight</mark>"), "highlight");
|
|
||||||
|
|
||||||
cooked(
|
cooked(
|
||||||
"[the answer](javascript:alert(42))",
|
"[the answer](javascript:alert(42))",
|
||||||
|
|
|
@ -226,6 +226,9 @@ module("Unit | Utility | to-markdown", function () {
|
||||||
html = `Have you tried clicking the <kbd>Help Me!</kbd> button?`;
|
html = `Have you tried clicking the <kbd>Help Me!</kbd> button?`;
|
||||||
assert.equal(toMarkdown(html), html);
|
assert.equal(toMarkdown(html), html);
|
||||||
|
|
||||||
|
html = `<mark>This is highlighted!</mark>`;
|
||||||
|
assert.equal(toMarkdown(html), html);
|
||||||
|
|
||||||
html = `Lorem <a href="http://example.com"><del>ipsum \n\n\n dolor</del> sit.</a>`;
|
html = `Lorem <a href="http://example.com"><del>ipsum \n\n\n dolor</del> sit.</a>`;
|
||||||
output = `Lorem [<del>ipsum dolor</del> sit.](http://example.com)`;
|
output = `Lorem [<del>ipsum dolor</del> sit.](http://example.com)`;
|
||||||
assert.equal(toMarkdown(html), output);
|
assert.equal(toMarkdown(html), output);
|
||||||
|
|
|
@ -194,6 +194,7 @@ export const DEFAULT_LIST = [
|
||||||
"ins",
|
"ins",
|
||||||
"kbd",
|
"kbd",
|
||||||
"li",
|
"li",
|
||||||
|
"mark",
|
||||||
"ol",
|
"ol",
|
||||||
"ol[start]",
|
"ol[start]",
|
||||||
"p",
|
"p",
|
||||||
|
|
|
@ -125,7 +125,8 @@ $quote-share-maxwidth: 150px;
|
||||||
}
|
}
|
||||||
|
|
||||||
del,
|
del,
|
||||||
ins {
|
ins,
|
||||||
|
mark {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +136,9 @@ $quote-share-maxwidth: 150px;
|
||||||
del {
|
del {
|
||||||
background-color: var(--danger-low);
|
background-color: var(--danger-low);
|
||||||
}
|
}
|
||||||
|
mark {
|
||||||
|
background-color: var(--highlight);
|
||||||
|
}
|
||||||
// Prevents users from breaking posts with tag nesting
|
// Prevents users from breaking posts with tag nesting
|
||||||
big {
|
big {
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
|
|
|
@ -180,7 +180,7 @@ class HtmlToMarkdown
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ALLOWED ||= %w{kbd del ins small big sub sup dl dd dt}
|
ALLOWED ||= %w{kbd del ins small big sub sup dl dd dt mark}
|
||||||
ALLOWED.each do |tag|
|
ALLOWED.each do |tag|
|
||||||
define_method("visit_#{tag}") do |node|
|
define_method("visit_#{tag}") do |node|
|
||||||
"<#{tag}>#{traverse(node)}</#{tag}>"
|
"<#{tag}>#{traverse(node)}</#{tag}>"
|
||||||
|
|
|
@ -205,6 +205,10 @@ describe HtmlToMarkdown do
|
||||||
expect(html_to_markdown("H<sub>2</sub>O")).to eq("H<sub>2</sub>O")
|
expect(html_to_markdown("H<sub>2</sub>O")).to eq("H<sub>2</sub>O")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "supports <mark>" do
|
||||||
|
expect(html_to_markdown("<mark>This is highlighted!</mark>")).to eq("<mark>This is highlighted!</mark>")
|
||||||
|
end
|
||||||
|
|
||||||
it "supports <sup>" do
|
it "supports <sup>" do
|
||||||
expect(html_to_markdown("<sup>Super Script!</sup>")).to eq("<sup>Super Script!</sup>")
|
expect(html_to_markdown("<sup>Super Script!</sup>")).to eq("<sup>Super Script!</sup>")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue