Files
speckle-server/packages/frontend-2/components/common/prose/GithubReadme.vue
T
andrewwallacespeckle c2a95b484f refactor(ui-components): define and use new font styles (#2524)
* New Text Styles. Initial FE2 changes

* More fe2 styling classes

* Minor update

* Minor update

* Fix build

* More updates for discussion

* More styling updates

* Minor updates to inputs

* More text updates

* More font class swapping

* Revert dui3 changes

* Confirmed Lineheights

* Add story files for new text styles

* Minor copy changes

* Minor typo

* andrew/web-1371-misalignment-in-account-dropdown

* andrew/web-1374-settings-text-styles-are-not-right

* andrew/web-1375-nav-texts-should-be-14px

* andrew/web-1376-decrease-size-of-versions-header

* andrew/web-1377-version-card-title

* semibold>medium

* Measure mode

* Changes from PR

* Tweaked nav menu

* Revert prose change. Add prose-sm

---------

Co-authored-by: Mike Tasset <mike.tasset@gmail.com>
2024-07-30 15:06:48 +01:00

72 lines
2.0 KiB
Vue

<!-- eslint-disable vue/no-v-html -->
<template>
<div
v-if="cleanReadmeHtml.length"
:class="proseClasses"
v-html="cleanReadmeHtml"
></div>
<div v-else class="italic text-center">No readme found</div>
</template>
<script setup lang="ts">
import type { Nullable } from '@speckle/shared'
import { useMarkdown } from '~/lib/common/composables/markdown'
const relativeLinkRegex = /\[(.+?)\]\(\/(.*?)\)/gi
const props = defineProps<{
readmeMarkdown: string
repo: string // e.g. 'specklesystems/speckle-server'
commitId?: string
}>()
const logger = useLogger()
const relativeLinkBaseUrl = computed(
() => `https://raw.githubusercontent.com/${props.repo}/${props.commitId || 'main'}/`
)
const finalMarkdown = computed(() => {
// Transform relative URLs to absolute URLs using the GitHub repo URL as a base URI
const source = props.readmeMarkdown
if (!source.length) return ''
// Find all relative links and append the repo URL to them
const newSource = source.replace(
relativeLinkRegex,
(match, linkText: Nullable<string>, relativePath: Nullable<string>) => {
let finalUrl = match
if (!linkText?.length || !relativePath?.length) return match
try {
const url = new URL(relativePath, relativeLinkBaseUrl.value).toString()
finalUrl = `[${linkText}](${url})`
} catch (e) {
logger.warn(e)
}
return finalUrl
}
)
return newSource
})
const { html: cleanReadmeHtml } = useMarkdown(
computed(() => finalMarkdown.value),
{ key: 'CommonProseGithubReadme' }
)
const proseClasses = ref([
'prose-sm max-w-none',
'prose-img:inline',
'prose-img:my-0',
'prose-h1:h2 prose-h1:font-medium prose-h1:mb-8',
'prose-h2:h3 prose-h2:font-medium prose-h2:mt-0 prose-h2:mb-6',
'prose-h3:h4 prose-h3:mb-4',
'prose-h4:h5 prose-h4:mb-4',
'prose-h5:h6 prose-h5:mb-4 prose-h5:font-medium',
'prose-h6:h6 prose-h6:mb-4 prose-h6:font-medium prose-h6:text-sm',
'dark:prose-invert'
])
</script>