-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from defstat/i9840-2
[UI-LIBRARY][main] #9840 Remove vue3-highlightjs and add "highlightjs/vue-plugin". Use only XML language.
- Loading branch information
Showing
6 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {Stories, Meta} from '@storybook/blocks'; | ||
|
||
import * as CodeHighlighterStories from './CodeHighlighter.stories.js'; | ||
|
||
<Meta of={CodeHighlighterStories} /> | ||
|
||
# CodeHighlighter | ||
|
||
## Usage | ||
|
||
Use this component to display a formatted segment of code | ||
|
||
## Supported Languages | ||
|
||
The supported languages include: | ||
|
||
- XML: `language="xml"` | ||
|
||
<Stories /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import CodeHighlighter from './CodeHighlighter.vue'; | ||
|
||
export default { | ||
title: 'Components/CodeHighlighter', | ||
component: CodeHighlighter, | ||
render: (args) => ({ | ||
components: {CodeHighlighter}, | ||
setup() { | ||
return {args}; | ||
}, | ||
template: '<code-highlighter :code=args.code :language=args.language />', | ||
}), | ||
}; | ||
|
||
const sampleXML = `<?xml version="1.0" encoding="UTF-8"?> | ||
<article> | ||
<title>Open Access in Research</title> | ||
<author> | ||
<name>Jane Doe</name> | ||
<affiliation>University of Knowledge</affiliation> | ||
</author> | ||
<journal> | ||
<name>Journal of Open Science</name> | ||
<year>2023</year> | ||
</journal> | ||
<doi>10.1234/jos.2023.001</doi> | ||
<license type="CC-BY">https://creativecommons.org/licenses/by/4.0/</license> | ||
<abstract> | ||
This paper explores the significance of open access in scientific research. | ||
</abstract> | ||
</article>`; | ||
|
||
export const XML = { | ||
args: { | ||
code: sampleXML, | ||
language: 'xml', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<template> | ||
<highlightjs :language="language" :code="code" /> | ||
</template> | ||
|
||
<script> | ||
import xml from 'highlight.js/lib/languages/xml'; | ||
import hljs from 'highlight.js/lib/core'; | ||
import hljsVuePlugin from '@highlightjs/vue-plugin'; | ||
hljs.registerLanguage('xml', xml); | ||
// A map to store language modules | ||
const languageMap = { | ||
xml, | ||
// Add more language modules imported above | ||
}; | ||
const supportedLanguages = Object.keys(languageMap); | ||
</script> | ||
|
||
<script setup> | ||
defineProps({ | ||
code: { | ||
type: String, | ||
required: true, | ||
}, | ||
language: { | ||
type: String, | ||
required: true, | ||
validator: (value) => { | ||
if (!supportedLanguages.includes(value)) { | ||
console.warn(`Invalid language prop: ${value}`); | ||
return false; | ||
} | ||
return true; | ||
}, | ||
}, | ||
}); | ||
const highlightjs = hljsVuePlugin.component; | ||
</script> | ||
|
||
<style> | ||
@import 'highlight.js/styles/github.css'; | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters