Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jovyntls committed Mar 18, 2023
1 parent 12eae43 commit 59e046a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 4 additions & 5 deletions packages/core/src/html/siteAndPageNavProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { v4 as uuidv4 } from 'uuid';
import { DomElement } from 'htmlparser2';
import cheerio from 'cheerio';
import { MbNode, parseHTML } from '../utils/node';
import { MbNode, NodeOrText, parseHTML, TextElement } from '../utils/node';

require('../patches/htmlparser2');
const md = require('../lib/markdown-it');
Expand Down Expand Up @@ -39,18 +38,18 @@ const SITE_NAV_DROPDOWN_ICON_ROTATED_HTML = '<div class="site-nav-dropdown-btn-c
* otherwise it is replaced with one until it is unique.
*/
export class PageNavProcessor {
uuidTextNode?: DomElement;
uuidTextNode?: TextElement;

getUuid() {
return (this.uuidTextNode && this.uuidTextNode.data) || '';
}

renderPageNav(node: MbNode) {
[this.uuidTextNode] = parseHTML(uuidv4());
cheerio(node).replaceWith(this.uuidTextNode as MbNode);
cheerio(node).replaceWith(this.uuidTextNode as cheerio.Element);
}

finalizePageNavUuid(mainHtml: string | null, mainHtmlNodes: DomElement[], footnotesHtml: string) {
finalizePageNavUuid(mainHtml: string | null, mainHtmlNodes: NodeOrText[], footnotesHtml: string) {
if (!this.uuidTextNode) {
return mainHtml;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/html/vueSlotSyntaxProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ export function shiftSlotNodeDeeper(node: MbNode) {
nodeChildren.forEach((child) => {
const vslotShorthandName = getVslotShorthandName(child);
if (vslotShorthandName && child.name !== 'template') {
const newSlotNode = parseHTML('<template></template>')[0];
const newSlotNode = parseHTML('<template></template>')[0] as MbNode;

const vslotShorthand = `#${vslotShorthandName}`;

newSlotNode.attribs = newSlotNode.attribs ?? {};
newSlotNode.attribs[vslotShorthand] = '';
if (child.attribs) {
delete child.attribs[vslotShorthand];
Expand All @@ -43,7 +42,7 @@ export function shiftSlotNodeDeeper(node: MbNode) {
newSlotNode.parent = node;
child.parent = newSlotNode;

newSlotNode.children = newSlotNode?.children ?? [];
newSlotNode.children = newSlotNode.children ?? [];
newSlotNode.children.push(child);

// replace the shifted old child node with the new slot node
Expand Down

0 comments on commit 59e046a

Please sign in to comment.