Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ if (process.env.VITE_CAPIRE_EXTRA_ASSETS) {
import { dl } from '@mdit/plugin-dl'
import * as MdAttrsPropagate from './lib/md-attrs-propagate'
import * as MdTypedModels from './lib/md-typed-models'
import * as MdDiagramSvg from './lib/md-diagram-svg'

config.markdown.config = md => {
MdAttrsPropagate.install(md)
MdTypedModels.install(md)
MdDiagramSvg.install(md)
md.use(dl)
}

Expand Down
51 changes: 51 additions & 0 deletions .vitepress/lib/md-diagram-svg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { MarkdownEnv, MarkdownRenderer } from 'vitepress'

/**
* Renders SVG diagrams in markdown files as <svg> element.
* This allows the diagrams to be interactive.
*
* To use, add `?raw` to the end of the image source, e.g. `![](diagram.svg?raw)`.
*/
export function install(md: MarkdownRenderer) {
const defaultImage =
md.renderer.rules.image ||
((tokens, idx, options, env, self) => self.renderToken(tokens, idx, options))

md.renderer.rules.image = (tokens, idx, options, env: MarkdownEnv, self) => {
const token = tokens[idx]
const src = token.attrGet('src') || ''

if (!/\.svg\?raw$/.test(src)) {
return defaultImage(tokens, idx, options, env, self)
}

const name = 'svg_' + src.replace('?raw', '').replace(/[^a-zA-Z0-9_]/g, '_') // stable variable name for the imported SVG content
const importPath = src.startsWith('/') && src.startsWith('.') ? src : './' + src

const sfcBlocks = env.sfcBlocks!
if (!sfcBlocks.scriptSetup) {
sfcBlocks.scriptSetup = {
content: '<script setup>\n</script>',
contentStripped: '\n',
tagClose: '</script>',
tagOpen: '<script setup>',
type: 'script'
}
sfcBlocks.scripts.push(sfcBlocks.scriptSetup)
}

const { scriptSetup } = sfcBlocks
const { tagOpen, tagClose, contentStripped: rest } = scriptSetup

const imp = `import ${name} from "${importPath}";`

if (!scriptSetup.content.includes(imp)) {
scriptSetup.contentStripped = `${imp}\n${rest}`
scriptSetup.content = `${tagOpen}${imp}\n${rest}${tagClose}`
}

// use v-html to render the SVG content as actual elements
// with v-html, vite's HMR update works on diagram change
return `<span class="diagram" v-html="${name}"></span>`
}
}
17 changes: 17 additions & 0 deletions .vitepress/theme/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ img, video.bright {
}
}

// Raw svg diagrams
.diagram {
all: initial; // preserve original svg formatting
svg {
.dark & { // recolor in dark mode
filter: brightness(.884) invert(1) hue-rotate(177deg);
}
max-width: 100%;
height: auto;
margin: 30px auto;

* {
// drawio line-height is not updated when font size is changed leading to misaligned text
line-height: unset !important;
}
}
}


.VPBadge {
Expand Down
869 changes: 865 additions & 4 deletions cds/assets/cxl/expr.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
319 changes: 145 additions & 174 deletions cds/assets/cxl/function.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 139 additions & 4 deletions cds/assets/cxl/infix-filter.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
657 changes: 653 additions & 4 deletions cds/assets/cxl/operators.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
194 changes: 190 additions & 4 deletions cds/assets/cxl/ref.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions cds/cxl.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ select from Books {

This syntax diagram describes the possible expressions:

![](assets/cxl/expr.drawio.svg)
![](assets/cxl/expr.drawio.svg?raw)

> Using:
> [Path Expressions](#ref),
Expand Down Expand Up @@ -262,7 +262,7 @@ A `ref` (short for reference) is used to refer to an element within the model.
It can be used to navigate along path segments. Such a navigation is often
referred to as a **path expression**.

![](assets/cxl/ref.drawio.svg)
![](assets/cxl/ref.drawio.svg?raw)

> Using:
> [Infix Filters](#infix-filters)
Expand Down Expand Up @@ -459,7 +459,7 @@ If we apply this terminology to [path-expressions](#ref), an infix filter condit
that is applied to a path-segment of a [path-expression](#ref).
This allows you to filter the target of an association based on certain criteria.

![](assets/cxl/infix-filter.drawio.svg)
![](assets/cxl/infix-filter.drawio.svg?raw)

> Using:
> [Expressions](#expr)
Expand Down Expand Up @@ -778,7 +778,7 @@ navigates along the `author` association of the `Books` entity only if the autho

As depicted in below excerpt of the syntax diagram for `expr`, CXL supports all the standard SQL operators as well as a few additional ones, such as the `?` operator to check for the existence of a path.

![](assets/cxl/operators.drawio.svg)
![](assets/cxl/operators.drawio.svg?raw)

> Using:
> [Expressions](#expr)
Expand Down Expand Up @@ -814,7 +814,7 @@ Following table gives an overview of the guaranteed supported operators in CXL:
## Functions (`func`)
###### func

![](assets/cxl/function.drawio.svg)
![](assets/cxl/function.drawio.svg?raw)

> Using:
> [Expressions](#expr)
Expand Down