Skip to content
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

StackExchange Markdown #175

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/viewer/src/components/Shared/SeMarkdown.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts">
export let source: string
Comment on lines +1 to +2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import format on line 2

const modify = (s: string) => {
const singlecurly = /{(?<type>[SPT])(?<id>\d+)}/g
const doublecurlies = /{{(?<prefix>\w)+:(?<id>[^{])+}}/g

// Replace single curly braces
s = s.replace(singlecurly, (type, id) => {
// Perform replacement based on type and id
return `${type}, ${id}`
})

// Replace double curly braces
s = s.replace(doublecurlies, (prefix, id) => {
// Perform replacement based on prefix and id
return `${prefix}, ${id}`
})
Comment on lines +14 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return format(...)


return s
}
</script>

<h4>StackExchange Markdown</h4>
<pre>
{modify(source)}
</pre>
4 changes: 4 additions & 0 deletions packages/viewer/src/components/Shared/Source.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import SeMarkdown from './SeMarkdown.svelte'
export let source: string
let showMarkdown = false
</script>
Expand All @@ -12,5 +13,8 @@
{#if showMarkdown}Hide{:else}Show{/if} markdown
</button>
{#if showMarkdown}
<h4>π-Base Markdown</h4>
<pre>{source}</pre>
<hr />
<SeMarkdown {source} />
{/if}
Loading