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

[core] atom.ui.markdown Refactor #893

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
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
49 changes: 20 additions & 29 deletions packages/markdown-preview/lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,21 @@ exports.toDOMFragment = async function (text, filePath, grammar, callback) {

} else {
// We use the new parser!
const domFragment = atom.ui.markdown.render(text,
const domFragment = await atom.ui.markdown.render(
text,
{
renderMode: "fragment",
filePath: filePath,
breaks: atom.config.get('markdown-preview.breakOnSingleNewline'),
useDefaultEmoji: true,
sanitizeAllowUnknownProtocols: atom.config.get('markdown-preview.allowUnsafeProtocols')
breaks: atom.config.get("markdown-preview.breakOnSingleNewline"),
emoji: true,
sanitize: true,
sanitizeAllowUnknownProtocols: atom.config.get("markdown-preview.allowUnsafeProtocols"),
highlight: scopeForFenceName,
defaultGrammar: grammar
}
);
const domHTMLFragment = atom.ui.markdown.convertToDOM(domFragment);
await atom.ui.markdown.applySyntaxHighlighting(domHTMLFragment,
{
renderMode: "fragment",
syntaxScopeNameFunc: scopeForFenceName,
grammar: grammar
}
);
)();

return domHTMLFragment;
return domFragment;
}
}

Expand All @@ -71,29 +67,24 @@ exports.toHTML = async function (text, filePath, grammar) {
return result
} else {
// We use the new parser!
const domFragment = atom.ui.markdown.render(text,
const domFragment = await atom.ui.markdown.render(
text,
{
renderMode: "full",
filePath: filePath,
breaks: atom.config.get('markdown-preview.breakOnSingleNewline'),
useDefaultEmoji: true,
sanitizeAllowUnknownProtocols: atom.config.get('markdown-preview.allowUnsafeProtocols')
breaks: atom.config.get("markdown-preview.breakOnSingleNewline"),
emoji: true,
sanitize: true,
sanitizeAllowUnknownProtocols: atom.config.get("markdown-preview.allowUnsafeProtocols"),
highlight: scopeForFenceName,
grammar: grammar
}
);
const domHTMLFragment = atom.ui.markdown.convertToDOM(domFragment);
)();

const div = document.createElement("div");
div.appendChild(domHTMLFragment);
div.appendChild(domFragment);
document.body.appendChild(div);

await atom.ui.markdown.applySyntaxHighlighting(div,
{
renderMode: "full",
syntaxScopeNameFunc: scopeForFenceName,
grammar: grammar
}
);

const result = div.innerHTML;
div.remove();

Expand Down
2 changes: 1 addition & 1 deletion packages/markdown-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"default": ""
},
"useOriginalParser": {
"description": "Wether to use the original Markdown Parser, or the new Pulsar one.",
"description": "Whether to use the original Markdown Parser, or the new Pulsar internal one.",
"type": "boolean",
"default": "true"
}
Expand Down
6 changes: 4 additions & 2 deletions packages/settings-view/lib/package-readme-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export default class PackageReadmeView {

const markdownOpts = {
breaks: false,
taskCheckboxDisabled: true,
useGitHubHeadings: true
taskCheckbox: true,
githubHeadings: true,
transformImageLinks: true,
transformNonFqdnLinks: true
};

if (readmeIsLocal) {
Expand Down
2 changes: 1 addition & 1 deletion packages/settings-view/lib/rich-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
return atom.ui.markdown.render(
description,
{
useTaskCheckbox: false,
taskCheckbox: false,
disableMode: "strict",
}
).replace(/<p>(.*)<\/p>/, "$1").trim();
Expand Down
23 changes: 18 additions & 5 deletions spec/ui-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,41 @@ describe("Renders Markdown", () => {
});

describe("transforms links correctly", () => {
const mdOpts = {
transformImageLinks: true,
transformNonFqdnLinks: true
};

it("makes no changes to a fqdn link", () => {
expect(atom.ui.markdown.render("[Hello World](https://github.com)"))
expect(atom.ui.markdown.render("[Hello World](https://github.com)", mdOpts))
.toBe('<p><a href="https://github.com">Hello World</a></p>\n');
});
it("resolves package links to pulsar", () => {
expect(atom.ui.markdown.render("[Hello](https://atom.io/packages/hey-pane)"))
expect(atom.ui.markdown.render("[Hello](https://atom.io/packages/hey-pane)", mdOpts))
.toBe('<p><a href="https://web.pulsar-edit.dev/packages/hey-pane">Hello</a></p>\n');
});
it("resolves atom links to web archive", () => {
expect(atom.ui.markdown.render("[Hello](https://flight-manual.atom.io/some-docs)"))
expect(atom.ui.markdown.render("[Hello](https://flight-manual.atom.io/some-docs)", mdOpts))
.toBe('<p><a href="https://web.archive.org/web/20221215003438/https://flight-manual.atom.io/some-docs">Hello</a></p>\n');
});
it("resolves incomplete local links", () => {
expect(atom.ui.markdown.render(
"[Hello](./readme.md)",
{ rootDomain: "https://github.com/pulsar-edit/pulsar" }
{
rootDomain: "https://github.com/pulsar-edit/pulsar",
transformImageLinks: true,
transformNonFqdnLinks: true
}
)).toBe('<p><a href="https://github.com/pulsar-edit/pulsar/blob/HEAD/readme.md">Hello</a></p>\n');
});
it("resolves incomplete root links", () => {
expect(atom.ui.markdown.render(
"[Hello](/readme.md)",
{ rootDomain: "https://github.com/pulsar-edit/pulsar" }
{
rootDomain: "https://github.com/pulsar-edit/pulsar",
transformImageLinks: true,
transformNonFqdnLinks: true
}
)).toBe('<p><a href="https://github.com/pulsar-edit/pulsar/blob/HEAD/readme.md">Hello</a></p>\n');
});
});
Expand Down
Loading
Loading