Skip to content

Commit

Permalink
fix(endpoint-micropub): don’t linkify incoming context text
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 7, 2023
1 parent ea1da90 commit 7128915
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/endpoint-micropub/lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const markdownToHtml = (string) => {
const options = {
html: true,
breaks: true,
linkify: true,
typographer: true,
};

Expand Down
6 changes: 3 additions & 3 deletions packages/endpoint-micropub/tests/unit/jf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ test("Gets content from `content.text` property", (t) => {
const result = getContentProperty(properties);

t.deepEqual(result, {
html: `<blockquote>\n<p>I ate a <a href="https://en.wikipedia.org/wiki/Cheese">cheese</a> sandwich from <a href="https://cafe.example">https://cafe.example</a>, which was &gt; 10.</p>\n</blockquote>\n<p>– Me, then.</p>`,
html: `<blockquote>\n<p>I ate a <a href="https://en.wikipedia.org/wiki/Cheese">cheese</a> sandwich from https://cafe.example, which was &gt; 10.</p>\n</blockquote>\n<p>– Me, then.</p>`,
text: "> I ate a [cheese](https://en.wikipedia.org/wiki/Cheese) sandwich from https://cafe.example, which was > 10.\n\n-- Me, then.",
});
});
Expand All @@ -185,7 +185,7 @@ test("Gets text content from `content` and adds HTML property", (t) => {
const result = getContentProperty(properties);

t.deepEqual(result, {
html: '<blockquote>\n<p>I ate a <a href="https://en.wikipedia.org/wiki/Cheese">cheese</a> sandwich from <a href="https://cafe.example">https://cafe.example</a>, which was &gt; 10.</p>\n</blockquote>\n<p>– Me, then.</p>',
html: '<blockquote>\n<p>I ate a <a href="https://en.wikipedia.org/wiki/Cheese">cheese</a> sandwich from https://cafe.example, which was &gt; 10.</p>\n</blockquote>\n<p>– Me, then.</p>',
text: "> I ate a [cheese](https://en.wikipedia.org/wiki/Cheese) sandwich from https://cafe.example, which was > 10.\n\n-- Me, then.",
});
});
Expand Down Expand Up @@ -452,7 +452,7 @@ test("Normalises JF2 (few properties)", (t) => {
t.is(result.name, "What I had for lunch");
t.is(result["mp-slug"], "what-i-had-for-lunch");
t.deepEqual(result.content, {
html: '<blockquote>\n<p>I ate a <a href="https://en.wikipedia.org/wiki/Cheese">cheese</a> sandwich from <a href="https://cafe.example">https://cafe.example</a>, which was &gt; 10.</p>\n</blockquote>\n<p>– Me, then.</p>',
html: '<blockquote>\n<p>I ate a <a href="https://en.wikipedia.org/wiki/Cheese">cheese</a> sandwich from https://cafe.example, which was &gt; 10.</p>\n</blockquote>\n<p>– Me, then.</p>',
text: "> I ate a [cheese](https://en.wikipedia.org/wiki/Cheese) sandwich from https://cafe.example, which was > 10.\n\n-- Me, then.",
});
t.falsy(result.audio);
Expand Down
38 changes: 34 additions & 4 deletions packages/endpoint-micropub/tests/unit/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,44 @@ import { markdownToHtml, htmlToMarkdown } from "../../lib/markdown.js";

test("Converts Markdown to HTML", (t) => {
t.is(
markdownToHtml("This is a **[link](#)**"),
'<p>This is a <strong><a href="#">link</a></strong></p>'
markdownToHtml("This is **strong**"),
"<p>This is <strong>strong</strong></p>"
);
t.is(
markdownToHtml("[Linked text](https://website.example)"),
'<p><a href="https://website.example">Linked text</a></p>'
);
t.is(
markdownToHtml("[https://website.example](https://website.example)"),
'<p><a href="https://website.example">https://website.example</a></p>'
);
t.is(
markdownToHtml("<https://website.example>"),
'<p><a href="https://website.example">https://website.example</a></p>'
);
t.is(
markdownToHtml("https://website.example"),
"<p>https://website.example</p>"
);
});

test("Converts HTML to Markdown", (t) => {
t.is(
htmlToMarkdown('<p>This is a <strong><a href="#">link</a></strong></p>'),
"This is a **[link](#)**"
htmlToMarkdown("<p>This is a <strong>strong</strong></p>"),
"This is a **strong**"
);
t.is(
htmlToMarkdown('<p><a href="https://website.example">Linked text</a></p>'),
"[Linked text](https://website.example)"
);
t.is(
htmlToMarkdown(
'<p><a href="https://website.example">https://website.example</a></p>'
),
"[https://website.example](https://website.example)"
);
t.is(
htmlToMarkdown("<p>https://website.example</p>"),
"https://website.example"
);
});

0 comments on commit 7128915

Please sign in to comment.