-
-
Notifications
You must be signed in to change notification settings - Fork 300
feat(texteditor): Markdown dual conversion for backward compatibility #5189
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
Merged
marcellamaki
merged 15 commits into
learningequality:unstable
from
habibayman:feat/RTE-markdown-conversion
Aug 22, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
dce292b
config: add tiptap-markdown dependency
habibayman 4086f59
feat(texteditor)[markdown]: configure bidirectional conversion
habibayman 52a1d8d
feat(texteditor)[markdwon]: create temp fake parent
habibayman d046056
refactor(texteditor): create custom markdown serializer
habibayman 4788ad2
refactor(texteditor): remove tiptap-markdown with related logic
habibayman 2bae21d
config: add marked to jest transformIgnorePatterns
habibayman 807c840
fix(texteditor)[markdown]: handle legacy images
habibayman 01f25a3
fix(texteditor)[markdown]: save img dimensions properly
habibayman e1100f1
Merge branch 'unstable' into feat/RTE-markdown-conversion
habibayman 4043ca0
tests(texteditor): write tests for loading custom markdown
habibayman c54c688
fix(markdown srializer): add depth to handle nested lists
habibayman 3ee5530
tests(texteditor): write tests for custom markdown serializer
habibayman 48a0bc4
refactor(texteditor)[image]: use lodash debounce
habibayman c50cd92
fix(texteditor)[serializer]: make markdown sticky to text
habibayman 59250bf
test(texteditor)[serializer]: test markdown stickiness to text
habibayman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import Vue from 'vue'; | ||
| import Router from 'vue-router'; | ||
| import TipTapEditor from '../shared/views/TipTapEditor/TipTapEditor/TipTapEditor.vue'; | ||
| import DevHarness from '../shared/views/TipTapEditor/TipTapEditor/DevHarness.vue'; | ||
|
|
||
| Vue.use(Router); | ||
| export default new Router({ | ||
| mode: 'history', | ||
| base: '/editor-dev/', | ||
| routes: [{ path: '/', component: TipTapEditor }], | ||
| routes: [{ path: '/', component: DevHarness }], | ||
| }); |
110 changes: 110 additions & 0 deletions
110
...ntcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/DevHarness.vue
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,110 @@ | ||
| <template> | ||
|
|
||
| <div class="dev-harness"> | ||
| <header class="harness-header"> | ||
| <h1>TipTap Editor - Development Harness</h1> | ||
| <p>This page simulates a parent component to test the editor in isolation.</p> | ||
| </header> | ||
| <hr > | ||
| <TipTapEditor v-model="markdownContent" /> | ||
| <hr > | ||
| <div class="raw-output-wrapper"> | ||
| <h2>Live Markdown Output (v-model state)</h2> | ||
| <pre>{{ markdownContent }}</pre> | ||
| </div> | ||
| </div> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| import { defineComponent, ref } from 'vue'; | ||
| import TipTapEditor from './TipTapEditor.vue'; | ||
|
|
||
| const SAMPLE_MARKDOWN = `# Testing basic & special nodes | ||
|
|
||
| **bold** *italic* <u>underline</u> ~~strikethrough~~ | ||
|
|
||
| try inline formulas $$x^2$$ test | ||
|
|
||
| - list a | ||
| - list b | ||
|
|
||
| <small class="small-text"> | ||
| small text | ||
| </small> | ||
|
|
||
| 1. list one<sub>[1]</sub> | ||
| 2. list two | ||
|
|
||
| There is a [link here](https://github.com/learningequality/studio/pull/5155/checks)! | ||
|
|
||
| \`\`\`javascript | ||
| export default html => { | ||
| const domParser = new DOMParser(); | ||
| const doc = domParser.parseFromString(html, 'text/html'); | ||
| const mdImages = doc.querySelectorAll('span[is="markdown-image-field"]'); | ||
|
|
||
| for (const mdImageEl of mdImages) { | ||
| mdImageEl.replaceWith(mdImageEl.innerHTML.trim()); | ||
| } | ||
|
|
||
| const editOptionButtons = doc.querySelectorAll('.ignore-md'); | ||
| for (const editOptionsEl of editOptionButtons) { | ||
| editOptionsEl.remove(); | ||
| } | ||
| return doc.body.innerHTML; | ||
| }; | ||
| \`\`\` | ||
| `; | ||
|
|
||
| export default defineComponent({ | ||
| name: 'DevHarness', | ||
| components: { | ||
| TipTapEditor, | ||
| }, | ||
| setup() { | ||
| // simulates the state of the parent component | ||
| const markdownContent = ref(SAMPLE_MARKDOWN); | ||
| return { markdownContent }; | ||
| }, | ||
| }); | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style scoped> | ||
|
|
||
| .dev-harness { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| padding: 20px; | ||
| } | ||
|
|
||
| .harness-header { | ||
| margin: 20px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .raw-output-wrapper { | ||
| width: 1000px; | ||
| padding: 1rem; | ||
| margin-top: 20px; | ||
| color: #f8f8f2; | ||
| background-color: #2d2d2d; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| .raw-output-wrapper h2 { | ||
| margin-top: 0; | ||
| color: #ffffff; | ||
| } | ||
|
|
||
| pre { | ||
| word-wrap: break-word; | ||
| white-space: pre-wrap; | ||
| } | ||
|
|
||
| </style> |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case for the parent component changing the content? Could/would this happen while I'm actively editing the content?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently no, it's not used anywhere.
I wrote it because my goal was to mimic a similar communication way to the one the old editor had with its parent.
The old editor didn't use
V-bindbut the data inside it was passed in both:Down(Parent to Editor)
The editor listens for changes on the markdown from the parent.
Check this piece of code.
Up(Editor to parent)
Native library event (
editor.on('change', ...)) -> Vue event (this.$emit('change', ...)) -> Parent handler (@change="...")I recreated the same logic using a different pattern,
I believe the "communication" method part finalization belongs more to the editor replacement issue #5206
so we'll be talking more about this in that PR giving it a closer look.