-
Notifications
You must be signed in to change notification settings - Fork 29
fix: markdown rendering for custom types #483
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
Open
sharanyavinod
wants to merge
7
commits into
main
Choose a base branch
from
ew-md
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b9c553
fix: markdown rendering for custom types
sharanyavinod d8e88bc
Merge branch 'main' into ew-md
sharanyavinod 90b6db8
fix: review comments
sharanyavinod 33e983a
Merge branch 'ew-md' of github-personal:adobe/da-nx into ew-md
sharanyavinod 74bb4c2
chore: code cleanup
sharanyavinod c433b01
fix: render progressively
sharanyavinod 8f4003d
Merge branch 'main' into ew-md
sharanyavinod 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| export function parseDirectives(text) { | ||
| const segments = []; | ||
| const buf = []; | ||
| let type = null; | ||
| let openLine = null; | ||
|
|
||
| for (const line of text.split('\n')) { | ||
| if (!type && line.startsWith(':::')) { | ||
| const extracted = line.slice(3).split(' ')[0]; | ||
| if (!extracted) { | ||
| buf.push(line); | ||
| } else { | ||
| const content = buf.splice(0).join('\n'); | ||
| if (content) segments.push({ kind: 'text', content }); | ||
| type = extracted; | ||
| openLine = line; | ||
| } | ||
| } else if (type && line.trimEnd() === ':::') { | ||
| segments.push({ kind: 'directive', type, content: buf.splice(0).join('\n') }); | ||
| type = null; | ||
| openLine = null; | ||
| } else { | ||
| buf.push(line); | ||
| } | ||
| } | ||
|
|
||
| if (openLine) { | ||
| segments.push({ kind: 'directive', type, content: buf.join('\n') }); | ||
| } else { | ||
| const tail = buf.join('\n'); | ||
| if (tail) segments.push({ kind: 'text', content: tail }); | ||
| } | ||
| return segments; | ||
| } |
File renamed without changes.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { expect } from '@esm-bundle/chai'; | ||
| import { parseDirectives } from '../../../../nx2/blocks/chat/utils/parse.js'; | ||
|
|
||
| describe('parseDirectives', () => { | ||
| describe('plain text', () => { | ||
| it('returns a single text segment for plain text', () => { | ||
| const result = parseDirectives('hello world'); | ||
| expect(result).to.deep.equal([{ kind: 'text', content: 'hello world' }]); | ||
| }); | ||
|
|
||
| it('returns empty array for empty string', () => { | ||
| expect(parseDirectives('')).to.deep.equal([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('single directive', () => { | ||
| it('parses a basic directive', () => { | ||
| const text = ':::checklist\n- [x] Done\n:::'; | ||
| expect(parseDirectives(text)).to.deep.equal([ | ||
| { kind: 'directive', type: 'checklist', content: '- [x] Done' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('parses a hyphenated type', () => { | ||
| const text = ':::alert-error\nSomething failed.\n:::'; | ||
| expect(parseDirectives(text)).to.deep.equal([ | ||
| { kind: 'directive', type: 'alert-error', content: 'Something failed.' }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('mixed content', () => { | ||
| it('handles text before a directive', () => { | ||
| const text = 'Intro text.\n:::list\n- item\n:::'; | ||
| const result = parseDirectives(text); | ||
| expect(result).to.deep.equal([ | ||
| { kind: 'text', content: 'Intro text.' }, | ||
| { kind: 'directive', type: 'list', content: '- item' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('handles text after a directive', () => { | ||
| const text = ':::list\n- item\n:::\nTrailing text.'; | ||
| const result = parseDirectives(text); | ||
| expect(result).to.deep.equal([ | ||
| { kind: 'directive', type: 'list', content: '- item' }, | ||
| { kind: 'text', content: 'Trailing text.' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('handles multiple directives', () => { | ||
| const text = ':::list\n- a\n:::\n:::checklist\n- [x] b\n:::'; | ||
| const result = parseDirectives(text); | ||
| expect(result).to.deep.equal([ | ||
| { kind: 'directive', type: 'list', content: '- a' }, | ||
| { kind: 'directive', type: 'checklist', content: '- [x] b' }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('bare ::: with no type', () => { | ||
| it('treats ::: with no type as plain text', () => { | ||
| expect(parseDirectives(':::')).to.deep.equal([{ kind: 'text', content: ':::' }]); | ||
| }); | ||
|
|
||
| it('does not open a directive scope for bare :::', () => { | ||
| const text = ':::\n:::checklist\n- item\n:::'; | ||
| const result = parseDirectives(text); | ||
| expect(result).to.deep.equal([ | ||
| { kind: 'text', content: ':::' }, | ||
| { kind: 'directive', type: 'checklist', content: '- item' }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('unclosed directive (streaming)', () => { | ||
| it('renders an unclosed directive as a directive with partial content', () => { | ||
| const text = ':::checklist\n- [x] partial'; | ||
| const result = parseDirectives(text); | ||
| expect(result).to.deep.equal([ | ||
| { kind: 'directive', type: 'checklist', content: '- [x] partial' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('renders completed and unclosed directives in order', () => { | ||
| const text = ':::list\n- done\n:::\n:::checklist\n- partial'; | ||
| const result = parseDirectives(text); | ||
| expect(result).to.deep.equal([ | ||
| { kind: 'directive', type: 'list', content: '- done' }, | ||
| { kind: 'directive', type: 'checklist', content: '- partial' }, | ||
| ]); | ||
| }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.