Skip to content

Commit

Permalink
[#103] Add support for the span tag
Browse files Browse the repository at this point in the history
  • Loading branch information
allenkinzalow committed Apr 3, 2024
1 parent d5dfbdf commit 8f05407
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`span node Span should parse and render 1`] = `"'''test'''"`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder";
import parse from "node-html-parser";

import spanParser from "../span";

describe("span node", () => {
test("Span should parse and render", () => {
const root = parse("<span><b>test</b></span>");
const builder = new MediaWikiBuilder();
builder.addContents([spanParser(root.firstChild)].flat());
expect(builder.build()).toMatchSnapshot();
});
});
2 changes: 2 additions & 0 deletions src/scrapers/news/sections/newsContent/nodes/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import linkParser from "./link";
import listParser from "./list";
import listItemParser from "./listItem";
import paragraphParser from "./paragraph";
import spanParser from "./span";
import tableParser from "./table";
import underlineParser from "./underline";
import videoParser from "./video";
Expand All @@ -36,6 +37,7 @@ const nodeParserMap: { [key: string]: ContentNodeParser } = {
li: listItemParser,
ol: listParser,
p: paragraphParser,
span: spanParser,
strong: boldParser,
table: tableParser,
u: underlineParser,
Expand Down
10 changes: 10 additions & 0 deletions src/scrapers/news/sections/newsContent/nodes/span.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import textParser from "./text";
import { ContentNodeParser } from "../types";

export const spanParser: ContentNodeParser = (node, options) => {
const children = textParser(node, options);
const childrenNodes = Array.isArray(children) ? children : [children];
return childrenNodes;
};

export default spanParser;

0 comments on commit 8f05407

Please sign in to comment.