Skip to content

Conversation

@marwie
Copy link
Contributor

@marwie marwie commented Jan 2, 2026

Related issue: 31933

Description

This PR adds a plugin to JSDoc to produce markdown files alongside the existing .html documentation pages and allows to append .md to docs URL hashes to open the markdown file. These files can then be used by LLMs to lookup information.

Example

Open questions

  1. Is this something three.js is even interested in since it adds some maintenance overhead?
  2. Currently the JSDoc plugin is vibecoded (at first I tried using jsdoc-to-markdown but wasn't happy with the result). Maybe the existing docs template could also produce the markdown file in the same plugin? Or should the HTML output be converted to markdown instead?
  3. What's missing is a llms.txt that contains links to the individual markdown files (similar to svelte llms.txt or stripe's llms.txt - the Stripe documentation works the same way https://docs.stripe.com/building-with-llms#llmstxt whereas Svelte does append /llms.txt e.g. https://svelte.dev/docs/svelte/what-are-runes/llms.txt).
  4. How about the other documentation pages (manual pages)? If accepted for the docs should all pages be available in markdown format?
  5. On a tangent: I noticed that threejs.org doesn't include a sitemap.xml and was wondering if this is something that should be added too (in a different PR)?

Motiviation:
I'm thinking about displaying some docs directly into the Needle Inspector extension or at least making it easier to query the relevant pages as markdown content when AI requests it.

This contribution is funded by Needle

Comment on lines +536 to +564
tempText = tempText
// Convert links (must be before stripping tags)
.replace(/<a[^>]*href="([^"]*)"[^>]*>([^<]*)<\/a>/g, '[$2]($1)')
// Convert code blocks
.replace(/<code>/g, '`')
.replace(/<\/code>/g, '`')
// Convert lists
.replace(/<li>/g, '- ')
.replace(/<\/li>/g, '\n')
.replace(/<ul>/g, '\n')
.replace(/<\/ul>/g, '\n')
.replace(/<ol>/g, '\n')
.replace(/<\/ol>/g, '\n')
// Convert paragraphs
.replace(/<p>/g, '')
.replace(/<\/p>/g, '\n\n')
// Convert breaks
.replace(/<br\s*\/?>/g, '\n')
// Convert strong/em
.replace(/<strong>/g, '**')
.replace(/<\/strong>/g, '**')
.replace(/<em>/g, '_')
.replace(/<\/em>/g, '_')
.replace(/<b>/g, '**')
.replace(/<\/b>/g, '**')
.replace(/<i>/g, '_')
.replace(/<\/i>/g, '_')
// Remove remaining HTML tags
.replace(/<[^>]+>/g, '')

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High documentation

This string may still contain
<script
, which may cause an HTML element injection vulnerability.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here isn't sanitization - besides that It's very possible that. a lot of this can actually be removed (or removed altogether if another solution like plugins like jsdoc-to-markdown are preferred)

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 2, 2026

I've shared a script for producing llms.txt files in #31933. It's in this comment. Isn't that sufficient?

@marwie
Copy link
Contributor Author

marwie commented Jan 2, 2026

Sufficient for the markdown files per html?

Maybe - I've tried it with the plugin at first (similar to the script you shared) but the output also seems to need some postprocessing to remove HTML or use a handlebars template:

e.g. here **Default**: <code>LoopRepeat</code> many places use <code> instead of backticks

or:

<dl>
<dt><a href="#ArrayNode">ArrayNode</a> ⇐ <code>TempNode</code></dt>
<dd><p>ArrayNode represents a collection of nodes, typically created using the <a href="#array">array</a> function.</p>
<pre><code class="language-js">const colors = array( [
    vec3( 1, 0, 0 ),
    vec3( 0, 1, 0 ),
    vec3( 0, 0, 1 )
] );

const redColor = tintColors.element( 0 );
</code></pre>
</dd>
</dl>

So I tried if directly writing markdown from jsdoc would be easier (which turned into this PR). Maybe the HTML in there is also totally fine - I'm not 100% sure.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 6, 2026

Closing in favor of #32673.

@Mugen87 Mugen87 closed this Jan 6, 2026
@Mugen87 Mugen87 added this to the r183 milestone Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants