Skip to content
Snippets Groups Projects
Commit d0bbe3ad authored by Thabo Bals's avatar Thabo Bals Committed by Cedric Greiten
Browse files

Make compiler happy

parent 31f55b4c
No related branches found
No related tags found
1 merge request!118Make compiler happy
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@types/markdown-it": "^14.1.2", "@types/markdown-it": "^14.1.2",
"@types/markdown-it-attrs": "^4.1.3",
"@types/markdown-it-emoji": "^3.0.1",
"@types/markdown-it-footnote": "^3.0.4",
"@types/node": "^22.10.10", "@types/node": "^22.10.10",
"bootstrap": "5.3.6", "bootstrap": "5.3.6",
"commander": "^14.0.0", "commander": "^14.0.0",
......
...@@ -11,6 +11,15 @@ importers: ...@@ -11,6 +11,15 @@ importers:
'@types/markdown-it': '@types/markdown-it':
specifier: ^14.1.2 specifier: ^14.1.2
version: 14.1.2 version: 14.1.2
'@types/markdown-it-attrs':
specifier: ^4.1.3
version: 4.1.3
'@types/markdown-it-emoji':
specifier: ^3.0.1
version: 3.0.1
'@types/markdown-it-footnote':
specifier: ^3.0.4
version: 3.0.4
'@types/node': '@types/node':
specifier: ^22.10.10 specifier: ^22.10.10
version: 22.15.19 version: 22.15.19
...@@ -336,6 +345,15 @@ packages: ...@@ -336,6 +345,15 @@ packages:
'@types/linkify-it@5.0.0': '@types/linkify-it@5.0.0':
resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==} resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==}
'@types/markdown-it-attrs@4.1.3':
resolution: {integrity: sha512-1JsseFdHD6rQHsPcy4W3xx/whxvZ09Z+CqPpnOtrGtpmkFW07N11q7oM383//LtoKv54yn+HGnk6r4ZHUTHJVg==}
'@types/markdown-it-emoji@3.0.1':
resolution: {integrity: sha512-cz1j8R35XivBqq9mwnsrP2fsz2yicLhB8+PDtuVkKOExwEdsVBNI+ROL3sbhtR5occRZ66vT0QnwFZCqdjf3pA==}
'@types/markdown-it-footnote@3.0.4':
resolution: {integrity: sha512-XJ6n+v+2u+2gmYLSHcxyoNT/YrgrKvHuDJQlykFjuxCQCr86P2/fx1V6/0lcKxv5cSIlCaJ6sUcNS3zDI7I+LA==}
'@types/markdown-it@14.1.2': '@types/markdown-it@14.1.2':
resolution: {integrity: sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==} resolution: {integrity: sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==}
...@@ -848,6 +866,18 @@ snapshots: ...@@ -848,6 +866,18 @@ snapshots:
'@types/linkify-it@5.0.0': {} '@types/linkify-it@5.0.0': {}
'@types/markdown-it-attrs@4.1.3':
dependencies:
'@types/markdown-it': 14.1.2
'@types/markdown-it-emoji@3.0.1':
dependencies:
'@types/markdown-it': 14.1.2
'@types/markdown-it-footnote@3.0.4':
dependencies:
'@types/markdown-it': 14.1.2
'@types/markdown-it@14.1.2': '@types/markdown-it@14.1.2':
dependencies: dependencies:
'@types/linkify-it': 5.0.0 '@types/linkify-it': 5.0.0
......
...@@ -217,7 +217,7 @@ async function generateAllTranscriptPages( ...@@ -217,7 +217,7 @@ async function generateAllTranscriptPages(
} }
async function generateTranscriptPage( async function generateTranscriptPage(
transcript, transcript: { meta: any; html: string; ast: any },
outputDir: string, outputDir: string,
options: CliOptions, options: CliOptions,
) { ) {
......
import { expect, describe, it, test } from "vitest"; import { describe, it } from "vitest";
import { parse } from "./parsing"; import { parse } from "./parsing";
import { writeFileSync } from "fs";
const exampleMarkdown = `
---
start: "xx"
---
TEST_MARKDOWN_BEFORE
[
Der FSR beschließt, X
]{.resolution .fin money-granted="150,00" yes=6 no=0 abstention=1 result=Angenommen}
TEST_MARKDOWN_AFTER
---
end: "yy"
---
`.trim();
const fullExampleMarkdown = ` const fullExampleMarkdown = `
--- ---
...@@ -290,6 +271,6 @@ end: "17:36" ...@@ -290,6 +271,6 @@ end: "17:36"
describe("Parsing", () => { describe("Parsing", () => {
it("parses", () => { it("parses", () => {
const { meta, html } = parse(fullExampleMarkdown); parse(fullExampleMarkdown);
}); });
}); });
...@@ -94,7 +94,7 @@ export function parseOld( ...@@ -94,7 +94,7 @@ export function parseOld(
})); }));
} }
function _endBlock(ast, start, level, close) { function _endBlock(ast: Token[], start: number, level: number, close: string) {
let end = start; let end = start;
for (end++; end < ast.length; end++) { for (end++; end < ast.length; end++) {
const token = ast[end]; const token = ast[end];
...@@ -197,7 +197,7 @@ export function parse(markdown: string): ParseResults { ...@@ -197,7 +197,7 @@ export function parse(markdown: string): ParseResults {
} }
// First off, check metadata: // First off, check metadata:
const { warnings, errors } = getMetadataProblems(data); const { errors } = getMetadataProblems(data);
if (errors.length > 0) { if (errors.length > 0) {
throw errors.join("\n"); throw errors.join("\n");
} }
...@@ -376,11 +376,19 @@ function extractHeaderMeta(token: Token): Map<string, string> { ...@@ -376,11 +376,19 @@ function extractHeaderMeta(token: Token): Map<string, string> {
return new Map(token.attrs); return new Map(token.attrs);
} }
function _extractMainClass(token: Token) { function _extractMainClass(token: Token): string | undefined {
return [...token.type.matchAll(/^container_(\S+)_open$/g)]?.[0]?.[1]; return token.type.match(/^container_(\S+)_open$/g)?.[1];
} }
function _extractBase(tokens: Token[], mainClass?: string) { function _extractBase(
tokens: Token[],
mainClass?: string,
): {
spanAttributes: Map<string, string>;
classes: Set<string>;
html: string;
text: string;
} {
if (tokens.length < 1) { if (tokens.length < 1) {
throw TypeError( throw TypeError(
"Parsing this requires an inline span with at least one child", "Parsing this requires an inline span with at least one child",
...@@ -389,7 +397,7 @@ function _extractBase(tokens: Token[], mainClass?: string) { ...@@ -389,7 +397,7 @@ function _extractBase(tokens: Token[], mainClass?: string) {
const duplicateAttrs = const duplicateAttrs =
tokens[0].attrs tokens[0].attrs
?.map(([k, v]) => k) ?.map(([k, _v]) => k)
.filter((k, i, a) => a.indexOf(k) !== i) ?? []; .filter((k, i, a) => a.indexOf(k) !== i) ?? [];
if (duplicateAttrs.length > 0) { if (duplicateAttrs.length > 0) {
throw TypeError( throw TypeError(
...@@ -428,8 +436,16 @@ function _extractBase(tokens: Token[], mainClass?: string) { ...@@ -428,8 +436,16 @@ function _extractBase(tokens: Token[], mainClass?: string) {
function tryExtractCards( function tryExtractCards(
tokens: Token[], tokens: Token[],
sharedState, sharedState: {
mainClass, nextResoNumbers: {
B: number;
F: number;
P: number;
};
resolutions: Resolution[];
data: FinishedTranscriptMeta;
},
mainClass?: string,
): Token | undefined { ): Token | undefined {
let rendered: undefined | string = undefined; let rendered: undefined | string = undefined;
...@@ -453,10 +469,10 @@ function tryExtractCards( ...@@ -453,10 +469,10 @@ function tryExtractCards(
other.match(/(^\d+)/)![1], other.match(/(^\d+)/)![1],
); );
if (otherTranscriptNumber > sharedState.data.number) if (otherTranscriptNumber > sharedState.data.number!)
return true; return true;
if (otherTranscriptNumber < sharedState.data.number) if (otherTranscriptNumber < sharedState.data.number!)
return false; return false;
const otherResolutionNumber = parseInt( const otherResolutionNumber = parseInt(
...@@ -490,7 +506,7 @@ function tryExtractCards( ...@@ -490,7 +506,7 @@ function tryExtractCards(
res.content = rendered; res.content = rendered;
return res; return res;
} else { } else {
const { spanAttributes, classes, html } = base; const { spanAttributes, classes } = base;
_assertEmpty(spanAttributes, "unknown card"); _assertEmpty(spanAttributes, "unknown card");
if ( if (
!["warning", "Meinungsbild", "GO-Antrag"].some((mainClass) => !["warning", "Meinungsbild", "GO-Antrag"].some((mainClass) =>
...@@ -503,7 +519,15 @@ function tryExtractCards( ...@@ -503,7 +519,15 @@ function tryExtractCards(
} }
} }
function tryExtractResolution(base, date): Resolution | null { function tryExtractResolution(
base: {
spanAttributes: Map<string, string>;
classes: Set<string>;
html: string;
text: string;
},
date: string,
): Resolution | null {
const { spanAttributes, classes, html, text } = base; const { spanAttributes, classes, html, text } = base;
if (!classes.delete("resolution")) { if (!classes.delete("resolution")) {
...@@ -673,7 +697,12 @@ function tryExtractResolution(base, date): Resolution | null { ...@@ -673,7 +697,12 @@ function tryExtractResolution(base, date): Resolution | null {
}; };
} }
function tryExtractNewTodo(base): Todo | null { function tryExtractNewTodo(base: {
spanAttributes: Map<string, string>;
classes: Set<string>;
html: string;
text: string;
}): Todo | null {
const { spanAttributes, classes, html, text } = base; const { spanAttributes, classes, html, text } = base;
if (!classes.delete("todo")) { if (!classes.delete("todo")) {
......
import { FinishedTranscriptMeta, Resolution, Todo } from "./parsing"; import { FinishedTranscriptMeta, Resolution, Todo } from "./parsing";
import { Attendance } from "./attendance"; import { Attendance } from "./attendance";
import Token from "markdown-it/lib/token.mjs";
export function renderContainerToAlert(context: String, title?: String) { export function renderContainerToAlert(context: String, title?: String) {
return function (tokens, idx) { return function (tokens: Token[], idx: number) {
return tokens[idx].nesting === 1 return tokens[idx].nesting === 1
? `<div class="alert ${context}" role="alert"">\n${ ? `<div class="alert ${context}" role="alert"">\n${
title === undefined title === undefined
...@@ -188,19 +189,19 @@ export function renderTranscriptPageHtml( ...@@ -188,19 +189,19 @@ export function renderTranscriptPageHtml(
<div class="col"> <div class="col">
<b>Anwesend:</b> <b>Anwesend:</b>
<ul> <ul>
${meta.present.map((p) => "<li>" + p + "</li>").join("\n")} ${meta.present.map((p: string) => "<li>" + p + "</li>").join("\n")}
</ul> </ul>
</div> </div>
<div class="col"> <div class="col">
<b>Abwesend:</b> <b>Abwesend:</b>
<ul> <ul>
${meta.absent.map((p) => "<li>" + p + "</li>").join("\n")} ${meta.absent.map((p: string) => "<li>" + p + "</li>").join("\n")}
</ul> </ul>
</div> </div>
<div class="col"> <div class="col">
<b>Gäste:</b> <b>Gäste:</b>
<ul> <ul>
${meta.guests.map((p) => "<li>" + p + "</li>").join("\n")} ${meta.guests.map((p: string) => "<li>" + p + "</li>").join("\n")}
</ul> </ul>
</div> </div>
</div> </div>
...@@ -445,7 +446,7 @@ function generateResolutionRowHtml( ...@@ -445,7 +446,7 @@ function generateResolutionRowHtml(
? `<a href="../protokolle/${transcriptFileName}/#${resolution.number}">${resolution.number}</a>` ? `<a href="../protokolle/${transcriptFileName}/#${resolution.number}">${resolution.number}</a>`
: `${resolution.number}`; : `${resolution.number}`;
let votes; let votes: string;
if (resolution.votes === undefined) { if (resolution.votes === undefined) {
votes = ""; votes = "";
} else if ( } else if (
......
...@@ -138,12 +138,12 @@ Der FSR beschließt, 700.2B aufzuheben. ...@@ -138,12 +138,12 @@ Der FSR beschließt, 700.2B aufzuheben.
]{.resolution yes=15 no=4 abstention=0 result=Angenommen revokes=700.2B modifies=700.2B} ]{.resolution yes=15 no=4 abstention=0 result=Angenommen revokes=700.2B modifies=700.2B}
[ [
Der FSR versucht beschluss 700.4B aufzuheben auf Der FSR versucht beschluss 700.3B aufzuheben auf
]{.resolution yes=0 no=19 abstention=0 result=Abgelehnt revokes=700.4B} ]{.resolution yes=0 no=19 abstention=0 result=Abgelehnt revokes=700.3B}
[ [
Der FSR hebt beschluss 700.4B auf Der FSR hebt beschluss 700.3B auf
]{.resolution yes=19 no=0 abstention=0 result=Angenommen revokes=700.4B} ]{.resolution yes=19 no=0 abstention=0 result=Angenommen revokes=700.3B}
# Sonstiges {start="12:39"} # Sonstiges {start="12:39"}
......
Subproject commit 949e022026129c1d8718fab752c1ff02dbca3c2c Subproject commit 1f1dbdfdfee3044e7921c0e57334a43493f298fd
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment