-
Couldn't load subscription status.
- Fork 2k
Feature: Add copy as markdown button to docs #3290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
DanOnCall
wants to merge
9
commits into
nestjs:master
from
DanOnCall:feature-add-copy-as-markdown-button-to-docs
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb8c726
refactor: Update styling and add copy as Markdown feature
DanOnCall 493f997
refactor: add states to copy button
DanOnCall ecafa25
feat: add domain to all images to make content portable
DanOnCall 0ad6b65
feat: remove angular comps from markdown
DanOnCall 208f8d1
feat: rename filter
DanOnCall 638dfd6
feat: parse @@filename and @@switch
DanOnCall bd533eb
feat: load md files on demand from static assets
DanOnCall 3673957
revert: Remove unused base64 filter from experimental approach
DanOnCall 77681b4
revert: Remove unused rawContent property from content reader
DanOnCall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
tools/transforms/content-package/processors/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './extractContentTitle'; | ||
| export * from './computeOutputPath'; | ||
| export * from './computeWhoUses'; | ||
| export * from './extractContentTitle'; | ||
| export * from './outputCleanMarkdown'; |
61 changes: 61 additions & 0 deletions
tools/transforms/content-package/processors/outputCleanMarkdown.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { writeFileSync, mkdirSync } from 'fs'; | ||
| import { dirname, join } from 'path'; | ||
| import { Processor } from 'dgeni'; | ||
| import { Document } from '../../shared'; | ||
|
|
||
| export class OutputCleanMarkdownProcessor implements Processor { | ||
| $runAfter = ['readFilesProcessor']; | ||
| $runBefore = ['renderDocsProcessor']; | ||
|
|
||
| $process(docs: Document[]) { | ||
| docs.forEach((doc) => { | ||
| if (doc.docType === 'content' && doc.content) { | ||
| // Clean the raw markdown content | ||
| const cleanedMarkdown = this.cleanMarkdown(doc.content); | ||
|
|
||
| // Output to src/assets/content/{id}.md so Angular can serve as assets | ||
| const outputPath = join('src/assets/content', `${doc.id}.md`); | ||
|
|
||
| // Ensure directory exists | ||
| mkdirSync(dirname(outputPath), { recursive: true }); | ||
|
|
||
| // Write cleaned markdown file | ||
| writeFileSync(outputPath, cleanedMarkdown, 'utf8'); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private cleanMarkdown(str: string): string { | ||
| return ( | ||
| str | ||
| // Fix image sources: /assets/... → https://docs.nestjs.com/assets/... | ||
| .replace(/src="(\/[^"]+)"/g, 'src="https://docs.nestjs.com1ドル"') | ||
| // Fix documentation links: [text](/some/path) → [text](https://docs.nestjs.com/some/path) | ||
| .replace(/\]\((\/[^)]+)\)/g, '](https://docs.nestjs.com1ドル)') | ||
| // Remove custom Angular components for cleaner portable markdown | ||
| .replace(/<app-[^>]*><\/app-[^>]*>/g, '') | ||
| // Convert @@filename to comments with .ts extension | ||
| .replace(/@@filename\(([^)]+)\)/g, (match, filename) => { | ||
| // Add .ts extension if filename doesn't already have a proper file extension | ||
| return filename.match( | ||
| /\.(ts|js|json|html|css|scss|yaml|yml|xml|dockerfile|md)$/i, | ||
| ) | ||
| ? `// ${filename}` | ||
| : `// ${filename}.ts`; | ||
| }) | ||
| // Remove empty filename placeholders | ||
| .replace(/@@filename\(\)/g, '') | ||
| // Split TypeScript/JavaScript versions into separate code blocks | ||
| .replace( | ||
| /@@switch\n?/g, | ||
| '```\n\nJavaScript version:\n\n```javascript\n', | ||
| ) | ||
| // Remove any empty lines left by component removal | ||
| .replace(/\n\s*\n\s*\n/g, '\n\n') | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export function outputCleanMarkdownProcessor() { | ||
| return new OutputCleanMarkdownProcessor(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.