From a5ffed4cd60d9d058d5374145c1176b10fad1660 Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Tue, 30 Jan 2024 16:36:55 +0100 Subject: [PATCH] Add markdown support for script/category names Add markdown rendering for script and category titles to improve the presentation of textual content. - Introduce reusable `MarkdownText` for markdown rendering. - Incorporate markdown styling into dedicated SCSS file for clarity. - Define explicit font sizes for consistent visual experience. - Apply `MarkdownText` usage across UI for unified markdown rendering. - Streamline related styles and layout for improved maintainability - Set font sizes explicitly for better consistency and to avoid unexpected inheritence. This enhancement enables richer text formatting and improves the user interface's flexibility in displaying content. --- .../Documentation/DocumentationText.vue | 181 ++---------------- .../ToggleDocumentationButton.vue | 2 + .../MarkdownRenderer.ts | 0 .../NodeContent/Markdown/MarkdownText.vue | 50 +++++ .../NodeContent/Markdown/markdown-styles.scss | 143 ++++++++++++++ .../View/Tree/NodeContent/NodeContent.vue | 10 +- .../View/Tree/NodeContent/NodeTitle.vue | 40 ++++ .../View/Tree/TreeView/Node/LeafTreeNode.vue | 12 -- .../MarkdownRenderer.spec.ts | 2 +- .../MarkdownRenderer.spec.ts | 2 +- 10 files changed, 259 insertions(+), 183 deletions(-) rename src/presentation/components/Scripts/View/Tree/NodeContent/{Documentation => Markdown}/MarkdownRenderer.ts (100%) create mode 100644 src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/MarkdownText.vue create mode 100644 src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/markdown-styles.scss create mode 100644 src/presentation/components/Scripts/View/Tree/NodeContent/NodeTitle.vue rename tests/integration/presentation/components/Scripts/View/Tree/NodeContent/{Documentation => Markdown}/MarkdownRenderer.spec.ts (96%) rename tests/unit/presentation/components/Scripts/View/Tree/NodeContent/{Documentation => Markdown}/MarkdownRenderer.spec.ts (99%) diff --git a/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/DocumentationText.vue b/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/DocumentationText.vue index 3a293a73..a6fb842a 100644 --- a/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/DocumentationText.vue +++ b/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/DocumentationText.vue @@ -1,17 +1,13 @@ - diff --git a/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/ToggleDocumentationButton.vue b/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/ToggleDocumentationButton.vue index 7ca89cf0..6ee5ade9 100644 --- a/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/ToggleDocumentationButton.vue +++ b/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/ToggleDocumentationButton.vue @@ -49,6 +49,8 @@ export default defineComponent({ .documentation-button { vertical-align: middle; color: $color-primary; + font-size: 24px; + :deep() { // This override leads to inconsistent highlight color, it should be re-styled. @include hover-or-touch { color: $color-primary-darker; diff --git a/src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/MarkdownRenderer.ts b/src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/MarkdownRenderer.ts similarity index 100% rename from src/presentation/components/Scripts/View/Tree/NodeContent/Documentation/MarkdownRenderer.ts rename to src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/MarkdownRenderer.ts diff --git a/src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/MarkdownText.vue b/src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/MarkdownText.vue new file mode 100644 index 00000000..26fe11f0 --- /dev/null +++ b/src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/MarkdownText.vue @@ -0,0 +1,50 @@ + + + + + diff --git a/src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/markdown-styles.scss b/src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/markdown-styles.scss new file mode 100644 index 00000000..48aed9af --- /dev/null +++ b/src/presentation/components/Scripts/View/Tree/NodeContent/Markdown/markdown-styles.scss @@ -0,0 +1,143 @@ +@use "@/presentation/assets/styles/main" as *; +@use 'sass:math'; + +@mixin code-block() { + pre { + @content; // :has(> code) { @content; } would be better, but Firefox doesn't support it https://caniuse.com/css-has + } +} + +@mixin inline-code() { + :not(pre) > code { + @content; + } +} + +@mixin code() { + code { + @content; + } +} + +@mixin no-margin($selectors) { + #{$selectors} { + margin: 0; + } +} + +@mixin no-padding($selectors) { + #{$selectors} { + padding: 0; + } +} + +@mixin left-padding($selectors, $horizontal-spacing) { + #{$selectors} { + padding-inline-start: $horizontal-spacing; + } +} + +@mixin bottom-margin($selectors, $vertical-spacing) { + #{$selectors} { + &:not(:last-child) { + margin-bottom: $vertical-spacing; + } + } +} + +@mixin apply-uniform-vertical-spacing($base-vertical-spacing) { + /* Reset default top/bottom margins added by browser. */ + @include no-margin('p'); + @include no-margin('h1, h2, h3, h4, h5, h6'); + @include no-margin('blockquote'); + @include no-margin('pre'); + + /* Add spacing between elements using `margin-bottom` only (bottom-up instead of top-down strategy). */ + $small-vertical-spacing: math.div($base-vertical-spacing, 2); + @include bottom-margin('p', $base-vertical-spacing); + @include bottom-margin('h1, h2, h3, h4, h5, h6', $base-vertical-spacing); + @include bottom-margin('ul, ol', $base-vertical-spacing); + @include bottom-margin('li', $small-vertical-spacing); + @include bottom-margin('table', $base-vertical-spacing); + @include bottom-margin('blockquote', $base-vertical-spacing); + @include bottom-margin('pre', $base-vertical-spacing); +} + +@mixin apply-uniform-horizontal-spacing($base-horizontal-spacing) { + /* Reset default left/right paddings added by browser. */ + @include no-padding('ul, ol'); + + /* Add spacing for list items. */ + $large-horizontal-spacing: $base-horizontal-spacing * 2; + @include left-padding('ul, ol', $large-horizontal-spacing); +} + +@mixin markdown-text-styles($text-size) { + $base-spacing: $text-size; + + a { + &[href] { + word-break: break-word; // Enables long URLs to wrap within the container, preventing horizontal overflow. + } + &[href^="http"]{ + &:after { + /* + Use mask element instead of content/background-image etc. + This way we can apply current font color to it to match the theme + */ + mask: url(@/presentation/assets/icons/external-link.svg) no-repeat 50% 50%; + mask-size: cover; + content: ''; + + display: inline-block; + width: $text-size; + height: $text-size; + + background-color: $text-color; + margin-left: math.div($text-size, 4); + } + /* + Match color of global hover behavior. We need to do it manually because global hover sets + `color` property but here we need to modify `background-color` property because color only + works if SVG is embedded as HTML element (as ``) not as `url(..)` as we do. Then the + only option is to use `mask` and `background-color` properties. + */ + @include hover-or-touch { + &::after{ + background-color: $color-highlight; + } + } + } + } + + @include code { + font-family: $font-normal; + font-weight: 600; + } + + @include inline-code { + word-break: break-all; // Enables inline code to wrap with the text, even for long single words (like registry paths), thus preventing overflow. + } + + @include code-block { + padding: $base-spacing; + background: $color-primary-darker; + overflow: auto; // Prevents horizontal expansion of inner content (e.g., when a code block is shown) + } + + @include apply-uniform-vertical-spacing($base-spacing); + @include apply-uniform-horizontal-spacing($base-spacing); + + ul { + /* + Set list style explicitly, because otherwise it changes based on parent