This commit is contained in:
Talon Poole 2021-02-24 21:05:27 +00:00
parent 2a75fc8223
commit 1bfb3e3715
2 changed files with 9 additions and 5 deletions

12
html.js
View file

@ -5,7 +5,11 @@ import * as CSS from "./css.js";
export const GMI_REGEX = /^((=>\s?(?<href>[^\s]+)\s?(?<title>.+)?)|(?<pre>```\s?(?<alt>.+)?)|(###\s?(?<h3>.+))|(##\s?(?<h2>.+))|(#\s?(?<h1>.+))|(\*\s?(?<li>.+))|(>\s?(?<quote>.+))|(?<text>(.+)?))$/;
export const tokenize = (gemtext) =>
JSON.parse(JSON.stringify(gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups)));
JSON.parse(
JSON.stringify(
gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups)
)
);
export function block(
{ text, href, title, pre, alt, h1, h2, h3, li, quote },
@ -42,15 +46,15 @@ export function block(
exts.some((ext) => new RegExp(`\.${ext}$`).test(url));
if (options.image && matchesExt(href, options.image)) {
type = "img";
props += ` src="${href}"`
props += ` src="${href}"`;
props += title ? ` title="${title}"` : "";
} else if (options.audio && matchesExt(href, options.audio)) {
type = "audio";
props += ` controls src="${href}"`
props += ` controls src="${href}"`;
props += title ? ` title="${title}"` : "";
} else if (options.video && matchesExt(href, options.video)) {
type = "video";
props += ` controls src="${href}"`
props += ` controls src="${href}"`;
props += title ? ` title="${title}"` : "";
} else {
type = "a";

View file

@ -75,7 +75,7 @@ test("--body", () => {
`);
});
test("--html en", () => {
test("--html en --author anon --description", () => {
expect(
toHTML(gemtext, {
html: "en",