Skip to content

Commit

Permalink
Fixes to ids
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Oct 26, 2023
1 parent 37ad396 commit c4f5ba3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/markdoc/partials/customPages/default-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The JS SDK is designed to streamline the experience for developers by providing

Below is a summary of the default values, their significance, and the associated parameters that can be adjusted as per your requirements:

{% defaultvalue title="executorOptions" description="Timeout for executing one task in ms." defaultValue="5 * 60 * 1000 = 5 min." /%}
## executorOptions

{% defaultvalue title="taskTimeout" description="Timeout for executing one task in ms." defaultValue="5 * 60 * 1000 = 5 min." /%}

Expand Down
8 changes: 8 additions & 0 deletions src/markdoc/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { Solution } from '@/components/Solution'
import { Problem } from '../components/Problem'
import { FeedbackButtons } from '@/components/Feedback'
import DefaultValue from '../components/DefaultValue'
import { slugifyWithCounter } from '@sindresorhus/slugify'
const slugify = slugifyWithCounter()
const tags = {
tabs: {
render: Tabs,
Expand All @@ -42,6 +44,12 @@ const tags = {
description: { type: String },
defaultValue: { type: String },
},
transform(node, config) {
const attributes = node.transformAttributes(config)
attributes.id = slugify(attributes.title)
const children = node.transformChildren(config)
return new Tag(this.render, attributes, children)
}
},
padding: {
render: Padding,
Expand Down
15 changes: 12 additions & 3 deletions src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ function collectHeadings(
let sections = []

for (let node of nodes) {
if (node.name === 'Heading' || (node.name === 'Defaultvalue' && node.attributes && node.attributes.title)) {
if (
node.name === 'Heading' ||
(node.name === 'Defaultvalue' && node.attributes && node.attributes.title)
) {
let level = node.name === 'Defaultvalue' ? 3 : node.attributes.level
let title = node.name === 'Defaultvalue' ? node.attributes.title : getNodeText(node)
let title =
node.name === 'Defaultvalue' ? node.attributes.title : getNodeText(node)

if (title) {
if (node.name === 'Defaultvalue') {
console.log(node)
}
let id = node.attributes?.id ?? slugify(title)
let newNode = { ...node.attributes, id, title, children: [], level }
if (lastNodes[level - 2]) {
Expand All @@ -46,7 +53,9 @@ function collectHeadings(
}
}

sections.push(...collectHeadings(node.children ?? [], slugify, lastNodes, idMap))
sections.push(
...collectHeadings(node.children ?? [], slugify, lastNodes, idMap)
)
}
return sections
}
Expand Down

0 comments on commit c4f5ba3

Please sign in to comment.