add warnings, quick fix

This commit is contained in:
Jon Dough
2023-06-19 21:58:32 +09:00
parent a5cfb04510
commit 15e5f0e916
3 changed files with 45 additions and 2 deletions

View File

@@ -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

View File

@@ -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 += `<a href="${link_href}">${link_content}</a>`;
was_link = true;
link_content = undefined;

10
web.ts
View File

@@ -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",