From 15e5f0e9164799c473db28b78c726fe56eaaa1cc Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+jetstream0@users.noreply.github.com> Date: Mon, 19 Jun 2023 21:58:32 +0900 Subject: [PATCH] add warnings, quick fix --- index.ts | 17 ++++++++++++++++- makoto.ts | 20 ++++++++++++++++++++ web.ts | 10 +++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index e6490e6..24764ff 100644 --- a/index.ts +++ b/index.ts @@ -28,7 +28,22 @@ Quirks /* List of warning types -- +- unknown-language +- image-incomplete +- link-incomplete +- italic-not-closed +- bold-not-closed +- superscript-not-closed +- blockquote-broken +- code-block-not-closed +- unordered-list-broken +- code-snippet-not-closed +- too-much-header +- heading-broken +- horizontal-rule-broken +- missing-image-alt +- empty-link +- weird-href */ //tests diff --git a/makoto.ts b/makoto.ts index a67d655..ae886d6 100644 --- a/makoto.ts +++ b/makoto.ts @@ -388,6 +388,12 @@ export function parse_md_to_html_with_warnings(md: string): ParseResult { } else if (char === " " && chars[i-1] === ">" && chars[i-2] === "\n") { //do not add the ' ' in '> ' to the html end_add_char = false; + } else if (char === ">" && chars[i+1] !== " " && (chars[i-1] === "\n" || i === 0)) { + warnings.push({ + type: "blockquote-broken", + message: "Missing space after `>` for blockquote?", + line_number, + }); } //code blocks if (char === "`" && chars[i+1] !== "`" && ((chars.slice(i-3, i) === "\n``" || (i === 2 && chars.slice(0, i) === "``")) || (in_blockquote && (chars.slice(i-5, i) === "\n> ``" || (i === 4 && chars.slice(0, i) === "> ``"))))) { @@ -465,6 +471,12 @@ export function parse_md_to_html_with_warnings(md: string): ParseResult { blockquote_list = true; } continue; + } else if (char !== " " && chars[i-1] === "-" && (chars[i-2] === "\n" || i === 1)) { + warnings.push({ + type: "unordered-list-broken", + message: "Missing space after unordered list", + line_number, + }); } //handle ordered lists let ol_num_length: number = String(ordered_list_num+1).length; @@ -669,6 +681,14 @@ export function parse_md_to_html_with_warnings(md: string): ParseResult { line_number, }); } + //":" includes protocols like http:// https:// wss:// and app uris + if (!link_href.includes(":") && !link_href.startsWith("./") && !link_href.startsWith("/")) { + warnings.push({ + type: "weird-href", + message: "Link href does not start with './' or '/' or contain ':', please double check it", + line_number, + }); + } html_line += `${link_content}`; was_link = true; link_content = undefined; diff --git a/web.ts b/web.ts index 6d05a95..2c27576 100644 --- a/web.ts +++ b/web.ts @@ -1,6 +1,14 @@ import { parse_md_to_html_with_warnings, ParseResult } from './makoto.js'; import type { Warning } from './endosulfan.js'; +/*todo: +- FIX not being able to delete at start of line when there is warning on the line +- show multiple warnings per line +- show warnings that do not have line number +- show warning type, ability to ignore warnings based on type +- keyboard shortcuts??? +*/ + let editor: HTMLTextAreaElement = document.getElementById("editor")! as HTMLTextAreaElement; let preview: HTMLElement = document.getElementById("rendered-text")!; let dark_theme_toggle: HTMLInputElement = document.getElementById("dark-theme-toggle")! as HTMLInputElement; @@ -77,7 +85,7 @@ if (params.get("help") === "true") { (editor.children[0] as HTMLElement).innerText = "# Makoto Markdown Parser"; let extra_lines: string[] = [ "This markdown parser is powered by spaghetti. You can have **bold text** or *italic text*, and even ^superscripts!^", - "Of course, you can have [links](https://en.wikipedia.org), and use backslashes to \*escape\*. Here's a list:", + "Of course, you can have [links](https://en.wikipedia.org), and use backslashes to \\*escape\\*. Here's a list:", "- uno", "- dos", "- tres",