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
3 changes: 1 addition & 2 deletions packages/litvis-integration-mume/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"block-attributes": "^0.5.0",
"block-info": "^0.5.0",
"cheerio": "1.0.0-rc.3",
"cheerio": "1.0.0-rc.12",
"elm-string-representation": "^2.0.0",
"html-entities": "^2.6.0",
"litvis": "^0.10.0",
Expand All @@ -33,7 +33,6 @@
"yamljs": "^0.3.0"
},
"devDependencies": {
"@types/cheerio": "0.22.21",
"@types/lodash": "4.17.20",
"@types/markdown-it": "14.1.2",
"@types/object-hash": "3.0.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BlockInfo } from "block-info";
import type { AnyNode, Cheerio, CheerioAPI } from "cheerio";
import cheerio from "cheerio";
import { encode } from "html-entities";
import type {
Expand Down Expand Up @@ -26,7 +27,7 @@ const flattenJsonToRawMarkdown = (data: unknown): string => {
return `${data}`;
};

const generate$output = (arrayOf$outputItems: Cheerio[]) => {
const generate$output = (arrayOf$outputItems: Array<Cheerio<AnyNode>>) => {
return cheerio(
'<div data-role="litvisOutput" style="display: inline;" />',
).append("", ...arrayOf$outputItems);
Expand Down Expand Up @@ -99,7 +100,7 @@ const mapAutogeneratedContextNames = (
};

export const enhanceWithLitvisLiterateElm = async (
$: CheerioStatic,
$: CheerioAPI,
processedNarrative: LitvisNarrative,
cache: LitvisEnhancerCache,
parseMd: ParseMd,
Expand All @@ -113,7 +114,7 @@ export const enhanceWithLitvisLiterateElm = async (
return;
}

const info: BlockInfo = $container.data("parsedInfo");
const info: BlockInfo = $container.data("parsedInfo") as BlockInfo;
if (`${info.language}`.toLowerCase() !== "elm") {
return;
}
Expand All @@ -134,8 +135,8 @@ export const enhanceWithLitvisLiterateElm = async (
$container.text(),
);

const arrayOf$outputItemsBeforeCodeBlock: Cheerio[] = [];
const arrayOf$outputItemsAfterCodeBlock: Cheerio[] = [];
const arrayOf$outputItemsBeforeCodeBlock: Array<Cheerio<AnyNode>> = [];
const arrayOf$outputItemsAfterCodeBlock: Array<Cheerio<AnyNode>> = [];
let currentArrayOf$outputItems = arrayOf$outputItemsBeforeCodeBlock;
derivativesWithResolvedExpressions.outputFormats.forEach((outputFormat) => {
switch (outputFormat) {
Expand Down Expand Up @@ -181,7 +182,7 @@ export const enhanceWithLitvisLiterateElm = async (
return;
}

const arrayOf$outputItems: Cheerio[] = [];
const arrayOf$outputItems: Array<Cheerio<AnyNode>> = [];
derivatives.outputFormats.forEach((outputFormat) => {
switch (outputFormat) {
case "l":
Expand Down Expand Up @@ -223,7 +224,9 @@ export const enhanceWithLitvisLiterateElm = async (
const mappedOutputItems = $outputItems.map(async (i, el) => {
const $el = $(el);
const contextName = $el.data("contextName");
const outputFormat: OutputFormat | undefined = $el.data("outputFormat");
const outputFormat: OutputFormat | undefined = $el.data("outputFormat") as
| OutputFormat
| undefined;
const expressionText = $el.data("expression");
const interactive = $el.data("interactive");
const renderKey = hash({
Expand All @@ -235,7 +238,7 @@ export const enhanceWithLitvisLiterateElm = async (
]!.path,
});
const context = contextsByMumeContextName[
contextName
contextName as string
] as ProcessedLitvisContext;
// const evaluatedOutputExpressionsByText = keyBy(context.evaluatedOutputExpressions, oe => oe.data.text);
try {
Expand Down Expand Up @@ -268,7 +271,7 @@ export const enhanceWithLitvisLiterateElm = async (
) {
throw new Error(`Could not parse value of ${expressionText}`);
}
let $result: Cheerio;
let $result: Cheerio<AnyNode>;
let resultNormalizedInfo: BlockInfo | null = null;
switch (outputFormat) {
case "r":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AnyNode, Cheerio, CheerioAPI } from "cheerio";
import type { LitvisNarrative } from "litvis";
import _ from "lodash";
import type { LabelNode } from "narrative-schema-label";
Expand All @@ -7,18 +8,18 @@ import { selectAll } from "unist-util-select";

import type { LitvisEnhancerCache } from "../types";

const markLabelAsErroneous = ($el: Cheerio, message: string) => {
const markLabelAsErroneous = ($el: Cheerio<AnyNode>, message: string) => {
$el.children().attr("style", "background: #fdd");
$el.attr("title", message);
};

export const enhanceWithLitvisNarrativeSchemas = async (
$: CheerioStatic,
$: CheerioAPI,
processedNarrative: LitvisNarrative,
cache: LitvisEnhancerCache,
): Promise<void> => {
// add styling from narrative schema
const arrayOf$StyleTags: Cheerio[] = [];
const arrayOf$StyleTags: Array<Cheerio<AnyNode>> = [];
if (processedNarrative.composedNarrativeSchema) {
arrayOf$StyleTags.push(
...getCssChunks(processedNarrative.composedNarrativeSchema).map(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BlockInfo } from "block-info";
import type { AnyNode, Cheerio, CheerioAPI } from "cheerio";
import type { LitvisNarrative } from "litvis";
import { extractAttributeDerivatives } from "litvis";
import YAML from "yamljs";
Expand All @@ -13,7 +14,7 @@ import type { LitvisEnhancerCache } from "../types";
* @param cache
*/
export const enhanceWithLitvisVegaBlockKeywords = async (
$: CheerioStatic,
$: CheerioAPI,
processedNarrative: LitvisNarrative,
cache: LitvisEnhancerCache,
): Promise<void> => {
Expand All @@ -23,11 +24,13 @@ export const enhanceWithLitvisVegaBlockKeywords = async (
return;
}

const info: BlockInfo = $container.data("parsedInfo");
const info: BlockInfo = $container.data("parsedInfo") as BlockInfo;
if (!info) {
return;
}
const normalizedInfo: BlockInfo = $container.data("normalizedInfo");
const normalizedInfo: BlockInfo = $container.data(
"normalizedInfo",
) as BlockInfo;
if (
normalizedInfo.language !== "vega" &&
normalizedInfo.language !== "vega-lite"
Expand Down Expand Up @@ -62,7 +65,7 @@ export const enhanceWithLitvisVegaBlockKeywords = async (
) {
return;
}
let $result: Cheerio | undefined;
let $result: Cheerio<AnyNode> | undefined;
let resultNormalizedInfo: (BlockInfo & { style?: string }) | undefined;
let resultText;
switch (outputFormat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CheerioAPI } from "cheerio";
import type { LitvisNarrative } from "litvis";

import type { LitvisEnhancerCache } from "../types";
Expand All @@ -8,7 +9,7 @@ import type { ParseMd } from "./helpers";

export const enhanceWithLitvis = async (
processedNarrative: LitvisNarrative,
$: CheerioStatic,
$: CheerioAPI,
cache: LitvisEnhancerCache,
parseMd: ParseMd,
): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AnyNode, Cheerio, CheerioAPI } from "cheerio";
import cheerio from "cheerio";
import { decode } from "html-entities";
import type { LitvisDocument, LitvisNarrative } from "litvis";
Expand All @@ -8,10 +9,10 @@ import type { Position } from "unist";
import type { VFile } from "vfile";

const findOrFilter = (
$: CheerioStatic,
func: (selector: string) => Cheerio,
$: CheerioAPI,
func: (selector: string) => Cheerio<AnyNode>,
selector: any,
): Cheerio => {
): Cheerio<AnyNode> => {
const cheerioSelectorParts: string[] = [];
if (selector) {
cheerioSelectorParts.push(`[ns-role="label"]`);
Expand All @@ -23,18 +24,34 @@ const findOrFilter = (
let $result = func(cheerioSelectorParts.join(""));
if (selector.trimmedContent) {
$result = $result.filter(
(i, element) => $(element).text().trim() === selector.trimmedContent,
(i, element) =>
$(element as AnyNode)
.text()
.trim() === selector.trimmedContent,
);
}

return $result;
};

const find = ($: CheerioStatic, $where: Cheerio, selector: any): Cheerio => {
const find = (
$: CheerioAPI,
$where: Cheerio<AnyNode>,
selector: any,
): Cheerio<AnyNode> => {
return findOrFilter($, $where.find.bind($where), selector);
};
const filter = ($: CheerioStatic, $what: Cheerio, selector: any): Cheerio => {
return findOrFilter($, $what.filter.bind($what), selector);
const filter = (
$: CheerioAPI,
$what: Cheerio<AnyNode>,
selector: any,
): Cheerio<AnyNode> => {
return findOrFilter(
$,
// @ts-expect-error - investigate type mismatch
$what.filter.bind($what),
selector,
);
};
const ruleIsNotFollowed = (
position?: Position,
Expand All @@ -49,7 +66,7 @@ const ruleIsNotFollowed = (
return result;
};

const elementPosition = ($el: Cheerio): Position | undefined => {
const elementPosition = ($el: Cheerio<AnyNode>): Position | undefined => {
const startColumn = parseInt($el.attr("ns-position-start-column") || "0", 10);
const startLine = parseInt($el.attr("ns-position-start-line") || "0", 10);
const endColumn = parseInt($el.attr("ns-position-end-column") || "0", 10);
Expand Down Expand Up @@ -122,7 +139,7 @@ export const postEnhanceWithLitvis = (

// single-element rules
$selection.each((i, el) => {
const $el = $(el);
const $el = $(el as AnyNode);
// children.minimumTrimmedTextLength
if (
ruleData.children &&
Expand Down
3 changes: 1 addition & 2 deletions packages/narrative-schema-label/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"block-attributes": "^0.5.0",
"block-info": "^0.5.0",
"cheerio": "1.0.0-rc.3",
"cheerio": "1.0.0-rc.12",
"data-with-position": "^0.5.0",
"handlebars": "^4.7.8",
"html-entities": "^2.6.0",
Expand All @@ -26,7 +26,6 @@
"vfile": "^4.2.1"
},
"devDependencies": {
"@types/cheerio": "0.22.21",
"@types/lodash": "4.17.20",
"@types/object-hash": "3.0.6",
"@types/unist": "2.0.6",
Expand Down
3 changes: 1 addition & 2 deletions packages/narrative-schema-rule/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"block-attributes": "^0.5.0",
"block-info": "^0.5.0",
"cheerio": "1.0.0-rc.3",
"cheerio": "1.0.0-rc.12",
"data-with-position": "^0.5.0",
"handlebars": "^4.7.8",
"html-entities": "^2.6.0",
Expand All @@ -24,7 +24,6 @@
"vfile": "^4.2.1"
},
"devDependencies": {
"@types/cheerio": "0.22.21",
"@types/lodash": "4.17.20"
}
}
5 changes: 1 addition & 4 deletions packages/narrative-schema-styling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
"dependencies": {
"block-attributes": "^0.5.0",
"block-info": "^0.5.0",
"cheerio": "1.0.0-rc.3",
"cheerio": "1.0.0-rc.12",
"data-with-position": "^0.5.0",
"handlebars": "^4.7.8",
"html-entities": "^2.6.0",
"lodash": "^4.17.21",
"narrative-schema-common": "^0.3.0",
"unist-util-visit": "^2.0.3",
"vfile": "^4.2.1"
},
"devDependencies": {
"@types/cheerio": "0.22.21"
}
}
Loading
Loading