Skip to content

Commit

Permalink
fix: use regex to find not parsed links
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquin Montes committed Sep 6, 2023
1 parent 392f2a5 commit 46514e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/actions/validate-docs-links/lib/index.js

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions .github/actions/validate-docs-links/src/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ type FailureFunction = (message: string) => void

const RELATIVE_PATH = '/'
const EXCLUDED_HASHES: string[] = []
const EXCLUDED_TAGS = ['a', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'code', 'img', 'iframe', 'nav', 'blockquote', 'hr', 'li', 'ol', 'pre', 'ul']

const slugger = new GithubSlugger()

Expand Down Expand Up @@ -195,6 +194,7 @@ function validateSourceLinks(doc: Document, errors: Errors): void {



let counter = 0

// Traverse the document tree and validate links
function traverseTreeAndValidateLinks(tree: any, doc: Document, setFailed: FailureFunction): Errors {
Expand All @@ -205,17 +205,18 @@ function traverseTreeAndValidateLinks(tree: any, doc: Document, setFailed: Failu
source: [],
related: [],
}

const linkRegex = /\[[^\[\]]+\]\([^\(\)]+\)/gm
function validateNodes (node: any, parse: boolean = false) {
if (node.type === 'text' && parse) {
// Handle links in custom components that were not correctly parsed
if (node.type === 'text' && linkRegex.test(node.value)) {
if (counter < 7) {
console.log('\n\n\nNODE: ',JSON.stringify(node))
counter++;
}
const customComponentTree = markdownProcessor.parse(node.value)
traverseRecursively(customComponentTree)
}

if (node.type === 'element' && !EXCLUDED_TAGS.includes(node.tagName)) {
node.children.forEach((child: any) => validateNodes(child, true))
}


if (node.type === 'element' && node.tagName === 'a' || node.type === 'link') {
const href = node.properties?.href ?? node.url
if (!href) return
Expand Down

0 comments on commit 46514e6

Please sign in to comment.