forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): improve documentation editor using Remirror (datahub-pr…
…oject#6631) Co-authored-by: Chris Collins <[email protected]>
- Loading branch information
1 parent
834369c
commit d227b6c
Showing
36 changed files
with
4,031 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
69 changes: 69 additions & 0 deletions
69
.../shared/tabs/Documentation/__tests__/components/editor/extensions/htmlToMarkdown.test.tsx
This file contains 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,69 @@ | ||
import { htmlToMarkdown } from '../../../../components/editor/extensions/htmlToMarkdown'; | ||
|
||
const cases = [ | ||
['strike', '<strike>Lorem ipsum</strike>', '~Lorem ipsum~'], | ||
['s', '<s>Lorem ipsum</s>', '~Lorem ipsum~'], | ||
['del', '<del>Lorem ipsum</del>', '~Lorem ipsum~'], | ||
[ | ||
'should replace blank nodes in table', | ||
'<table><thead><tr><th>Lorem ipsum</th></tr></thead><tbody><tr><td><p>Lorem</p><p>ipsum</p></td></tr></tbody></table>', | ||
'| Lorem ipsum |\n| --- |\n| Lorem<br />ipsum |', | ||
], | ||
['should replace empty p tags to line breaks', '<p>Lorem</p><p></p><p>ipsum</p>', 'Lorem\n\n \n\nipsum'], | ||
[ | ||
'should parse image if it does not have a width attribute', | ||
'<img src="/my-image.png" style="width: 100%; min-width: 50px; object-fit: contain;" alt="my image">', | ||
'![my image](/my-image.png)', | ||
], | ||
|
||
[ | ||
'should highlight code block with html', | ||
'<pre><code class="language language-html"><<span class="pl-ent">p</span>>Hello world</<span class="pl-ent">p</span>></code></pre>', | ||
'```html\n<p>Hello world</p>\n```', | ||
], | ||
[ | ||
'should highlight code block with js', | ||
'<pre><code class="lang lang-js">;(<span class="pl-k">function</span> () {})()</code></pre>', | ||
'```js\n;(function () {})()\n```', | ||
], | ||
[ | ||
'should highlighted remirror code block', | ||
'<pre><code data-code-block-language="ts">;(<span class="pl-k">function</span> () {})()</code></pre>', | ||
'```ts\n;(function () {})()\n```', | ||
], | ||
[ | ||
'should parse without language code block', | ||
'<pre><code>;(<span class="pl-k">function</span> () {})()</code></pre>', | ||
'```\n;(function () {})()\n```', | ||
], | ||
[ | ||
'should parse datahub mention', | ||
'<span class="mentions" data-datahub-mention-urn="urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)">@SampleHiveDataset</span>', | ||
'[@SampleHiveDataset](urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD))', | ||
], | ||
]; | ||
|
||
const skipParseCases = [ | ||
[ | ||
'table if ul or li is present', | ||
'<table><thead><tr><th>Lorem ipsum</th></tr></thead><tbody><tr><td><ul><li>Lorem</li><li>ipsum</li></ul></td></tr></tbody></table>', | ||
], | ||
[ | ||
'table if present', | ||
'<table><thead><tr><th>Lorem ipsum</th></tr></thead><tbody><tr><td><ul><li>Lorem</li><li>ipsum</li></ul></td></tr></tbody></table>', | ||
], | ||
[ | ||
'image if it has a width attribute', | ||
'<img src="/my-image.png" style="width: 100%; min-width: 50px; object-fit: contain;" alt="my image" width="200">', | ||
], | ||
]; | ||
|
||
describe('htmlToMarkdown', () => { | ||
it.each(cases)('%s', (_, input, expected) => { | ||
expect(htmlToMarkdown(input)).toBe(expected); | ||
}); | ||
|
||
it.each(skipParseCases)('should skip parsing %s', (_, input) => { | ||
expect(htmlToMarkdown(input)).toBe(input); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
.../shared/tabs/Documentation/__tests__/components/editor/extensions/markdownToHtml.test.tsx
This file contains 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,21 @@ | ||
import { markdownToHtml } from '../../../../components/editor/extensions/markdownToHtml'; | ||
|
||
const cases = [ | ||
[ | ||
'should parse datahub mentions', | ||
'Lorem [@SampleHiveDataset](urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)) ipsum', | ||
'<p>Lorem <span data-datahub-mention-urn="urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)">@SampleHiveDataset</span> ipsum</p>\n', | ||
], | ||
['should not parse github mentions', 'Lorem @githubuser ipsum', '<p>Lorem @githubuser ipsum</p>\n'], | ||
[ | ||
'should parse invalid mentions as links', | ||
'Lorem [@Some link](/lorem-ipsum) ipsum', | ||
'<p>Lorem <a href="/lorem-ipsum">@Some link</a> ipsum</p>\n', | ||
], | ||
]; | ||
|
||
describe('markdownToHtml', () => { | ||
it.each(cases)('%s', (_, input, expected) => { | ||
expect(markdownToHtml(input)).toBe(expected); | ||
}); | ||
}); |
Oops, something went wrong.