Skip to content

Commit

Permalink
move marked dependency (#2240)
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz authored Apr 9, 2019
1 parent 3d99934 commit 260c9e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
25 changes: 24 additions & 1 deletion src/core/markdown.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
/**
* Module core/markdown
* Handles the optional markdown processing.
Expand Down Expand Up @@ -43,9 +44,31 @@
* The whitespace of pre elements are left alone.
*/

import { markdownToHtml } from "./utils.js";
import marked from "marked";
import { normalizePadding } from "./utils.js";
export const name = "core/markdown";

const gtEntity = />/gm;
const ampEntity = /&/gm;

/**
* @param {string} text
*/
export function markdownToHtml(text) {
const normalizedLeftPad = normalizePadding(text);
// As markdown is pulled from HTML, > and & are already escaped and
// so blockquotes aren't picked up by the parser. This fixes it.
const potentialMarkdown = normalizedLeftPad
.replace(gtEntity, ">")
.replace(ampEntity, "&");
const result = marked(potentialMarkdown, {
sanitize: false,
gfm: true,
headerIds: false,
});
return result;
}

function processElements(selector) {
return element => {
const elements = Array.from(element.querySelectorAll(selector));
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import css from "text!../../assets/ui.css";
import hyperHTML from "hyperhtml";
import { markdownToHtml } from "./utils.js";
import { markdownToHtml } from "./markdown.js";
import shortcut from "../shortcut.js";
import { sub } from "./pubsubhub.js";
export const name = "core/ui";
Expand Down
20 changes: 0 additions & 20 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,12 @@
// As the name implies, this contains a ragtag gang of methods that just don't fit
// anywhere else.
import { lang as docLang } from "./l10n.js";
import marked from "marked";
import { pub } from "./pubsubhub.js";
export const name = "core/utils";

marked.setOptions({
sanitize: false,
gfm: true,
headerIds: false,
});

const spaceOrTab = /^[ |\t]*/;
const endsWithSpace = /\s+$/gm;
const dashes = /-/g;
const gtEntity = />/gm;
const ampEntity = /&/gm;

export function markdownToHtml(text) {
const normalizedLeftPad = normalizePadding(text);
// As markdown is pulled from HTML, > and & are already escaped and
// so blockquotes aren't picked up by the parser. This fixes it.
const potentialMarkdown = normalizedLeftPad
.replace(gtEntity, ">")
.replace(ampEntity, "&");
const result = marked(potentialMarkdown);
return result;
}

export const ISODate = new Intl.DateTimeFormat(["en-ca-iso8601"], {
timeZone: "UTC",
Expand Down

0 comments on commit 260c9e7

Please sign in to comment.