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
27 changes: 26 additions & 1 deletion packages/nstreamdown/vue/components/CodeBlock.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { ref, watch, onMounted } from 'vue';
import { isIOS } from '@nativescript/core';
import { isIOS, isAndroid } from '@nativescript/core';
import { copyToClipboard } from '@nstudio/nstreamdown';

// Declare iOS types available at runtime
Expand Down Expand Up @@ -55,6 +55,29 @@ function applyHighlighting() {
}
}

// Android - use native Kotlin syntax highlighter
if (isAndroid) {
try {
const androidLabel = codeLabel.value.android;
if (androidLabel && typeof org !== 'undefined' && org.nativescript?.streamdown?.SyntaxHighlighter) {
const highlighter = org.nativescript.streamdown.SyntaxHighlighter.getShared();
const scheme = org.nativescript.streamdown.SyntaxHighlighter.getDarkScheme();

// Reduce line spacing to match iOS (1.0 = single spacing, no extra)
androidLabel.setLineSpacing(0, 1.0);

// Use synchronous highlight for immediate display
const spannableString = highlighter.highlight(props.code, props.language || 'typescript', scheme);
if (spannableString) {
androidLabel.setText(spannableString, android.widget.TextView.BufferType.SPANNABLE);
return;
}
}
} catch (e) {
console.log('[CodeBlock] Android Syntax highlighting error:', e);
}
}

// Fallback - just set text
codeLabel.value.text = props.code;
}
Expand Down Expand Up @@ -85,11 +108,13 @@ watch(() => props.language, () => {
<GridLayout row="0" columns="*, auto" class="bg-slate-800 border-b border-slate-700 px-3 py-2">
<Label col="0" :text="language || 'code'" class="text-xs text-slate-400 font-mono" />
<Image
v-if="isIOS"
:src="copied ? 'sys://checkmark.circle' : 'sys://document.on.document'"
col="1"
class="w-4 h-4 text-blue-400"
@tap="onCopy"
/>
<Label v-else col="1" :text="copied ? '✓' : '📋'" class="text-base text-blue-400 px-1 h-[18]" @tap="onCopy"></Label>
</GridLayout>

<!-- Code content with native syntax highlighting -->
Expand Down
3 changes: 2 additions & 1 deletion packages/nstreamdown/vue/components/MdMermaid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isIOS, WebView } from '@nativescript/core';
import {
copyToClipboard,
generateMermaidHTML,
RoundedOutlineProvider,
configureIOSWebViewForMermaid,
configureAndroidWebViewForMermaid,
loadMermaidIntoIOSWebView,
Expand Down Expand Up @@ -86,7 +87,7 @@ function onContainerLoaded(args: any) {
const density = android.content.res.Resources.getSystem().getDisplayMetrics().density;
const radiusPx = 12 * density;
// @ts-ignore
const provider = new org.nativescript.streamdown.RoundedOutlineProvider(radiusPx);
const provider = new RoundedOutlineProvider(radiusPx);
nativeView.setOutlineProvider(provider);
nativeView.setClipToOutline(true);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nstreamdown/vue/components/Streamdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function onLinkTap(token: MarkdownToken) {

<!-- Mermaid diagrams -->
<MdMermaid
v-else-if="token.type === 'mermaid-block'"
v-else-if="token.type === 'mermaid'"
:content="token.content"
:darkMode="true"
:isIncomplete="getIsIncomplete(token)"
Expand Down