Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/core/data-include.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function fillWithText(el, data, { replace }) {
const { includeFormat } = el.dataset;
let fill = data;
if (includeFormat === "markdown") {
fill = markdownToHtml(fill);
fill = markdownToHtml(fill, { fromHTML: false });
}

if (includeFormat === "text") {
Expand Down
16 changes: 11 additions & 5 deletions src/core/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,21 @@ function normalizeIndent(text) {
/**
* @param {string} text
* @param {object} options
* @param {boolean} options.inline
* @param {boolean} [options.inline]
* @param {boolean} [options.fromHTML]
*/
export function markdownToHtml(text, options = { inline: false }) {
export function markdownToHtml(
text,
options = { inline: false, fromHTML: true }
) {
const normalizedLeftPad = normalizeIndent(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, "&");
// When text comes from a raw fetch (data-include), skip this step.
const potentialMarkdown =
options.fromHTML !== false
? normalizedLeftPad.replace(gtEntity, ">").replace(ampEntity, "&")
: normalizedLeftPad;

const result = options.inline
? marked.parseInline(potentialMarkdown, config)
Expand Down