Skip to content

Commit

Permalink
Fix different language highlight + add option to skip highlighting + …
Browse files Browse the repository at this point in the history
…don't highlight markdown code
  • Loading branch information
AydinHassan committed Mar 20, 2024
1 parent 62cc9de commit 5d3b621
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions assets/components/Website/Docs/CodeBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@ import { highlightCode } from "../../../helpers/highlightCode";
import { TransitionRoot } from "@headlessui/vue";
import { ClipboardDocumentIcon } from "@heroicons/vue/24/solid";
const language = ref("php");
const formattedCode = ref("");
const code = ref(slots.default()[0].children);
const props = defineProps({
lang: {
type: String,
default: "php",
},
noHighlight: {
type: Boolean,
default: false,
},
});
const highlight = () => {
formattedCode.value = highlightCode(code.value, language.value);
if (props.noHighlight === true) {
formattedCode.value = code.value;
return;
}
formattedCode.value = highlightCode(code.value, props.lang);
};
onMounted(() => {
Expand Down Expand Up @@ -66,7 +81,7 @@ const clipboardAvailable = computed(() => {
<span class="absolute right-4 top-4 font-mono text-[10px] text-pink-600">Copied!</span>
</TransitionRoot>
<div class="mb-4 overflow-y-scroll rounded-md border border-gray-600 bg-gray-900 p-4">
<pre><code class="block text-xs " :class="language" v-html="formattedCode"></code></pre>
<pre><code class="block text-xs" :class="lang" v-html="formattedCode"></code></pre>
</div>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ echo $count / $numberCount;</pre
</ul>

<p>Our problem file might look like the following.</p>
<CodeBlock lang="md">
<CodeBlock lang="md" no-highlight>
<pre>
Write a program that accepts one or more numbers as command-line arguments and prints the mean average of those numbers to the console (stdout).

Expand Down

0 comments on commit 5d3b621

Please sign in to comment.