nextcloud-vue icon indicating copy to clipboard operation
nextcloud-vue copied to clipboard

Add `stripMarkdown` method for text parsing

Open Antreesy opened this issue 11 months ago • 4 comments

Can be done with unified plugin https://github.com/remarkjs/strip-markdown, which we already using (in NcRichText) Method needs to be exportable (as function / util / composable) to be used in apps and projects

  • [ ] Might be a part of NcRichPlainText component (if implemented)

Antreesy avatar Jan 24 '25 08:01 Antreesy

Is there a place where we need to get the text and cannot render a component? If there isn't, we can add is as a prop of NcRichText

ShGKme avatar Jan 24 '25 09:01 ShGKme

See these places in Talk:

https://github.com/nextcloud/spreed/blob/d6d279881b93c3a15f8b5f61b179bbb501c56467/src/components/LeftSidebar/ConversationsList/Conversation.vue#L42-L43

https://github.com/nextcloud/spreed/blob/af08e225f6a0ea71171eb7bbaf11c1be11e737f3/src/components/TopBar/TopBar.vue#L45-L49

Though I don't feel like it makes sense to pull all the NcRichText logic in these places, if it can be done in easier way

Antreesy avatar Jan 24 '25 10:01 Antreesy

See these places in Talk:

Both look like rendering content and don't require JS API.

to pull all the NcRichText logic

We have the component in the bundle anyway. And the logic isn't executed until we enable MD rendering.

if it can be done in easier way

That's why I'd propose to do

<NcRichText :text strip-markdown />

instead of

<!-- eslint-disable-next-line vue/no-v-html -->
<p v-html="textWithoutMarkdown" />

<script setup>
import { stripMarkdown } from '@nextcloud/vue/functions/stripMarkdown'

const textWithoutMarkdown = computed(() => stripMarkdown(text))
</script>

ShGKme avatar Jan 24 '25 15:01 ShGKme

Yes this would make sense also for some apps, e.g. where we render a preview of markdown text as second line of list item.

susnux avatar Jan 27 '25 12:01 susnux