Skip to content

Commit 42f1ed2

Browse files
committed
polish
1 parent c11aaa4 commit 42f1ed2

File tree

3 files changed

+32
-51
lines changed

3 files changed

+32
-51
lines changed

apps/demo-angular/src/app/demos/streamdown-demo.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,38 @@
44
*/
55
import { Component, NO_ERRORS_SCHEMA, ChangeDetectionStrategy, signal, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/core';
66
import { NativeScriptCommonModule, RouterExtensions } from '@nativescript/angular';
7-
import { ScrollView, isIOS } from '@nativescript/core';
7+
import { ScrollView, isIOS, isAndroid } from '@nativescript/core';
88
import { Streamdown } from '@nstudio/nstreamdown/angular';
99
import type { StreamdownConfig } from '@nstudio/nstreamdown/angular';
1010

11+
// Platform-specific code example
12+
const PLATFORM_CODE_EXAMPLE = isIOS
13+
? `And here's some Swift for iOS:
14+
15+
\`\`\`swift
16+
import UIKit
17+
18+
class ViewController: UIViewController {
19+
override func viewDidLoad() {
20+
super.viewDidLoad()
21+
print("Hello from NativeScript!")
22+
}
23+
}
24+
\`\`\``
25+
: `And here's some Kotlin for Android:
26+
27+
\`\`\`kotlin
28+
import android.os.Bundle
29+
import androidx.appcompat.app.AppCompatActivity
30+
31+
class MainActivity : AppCompatActivity() {
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
super.onCreate(savedInstanceState)
34+
println("Hello from NativeScript!")
35+
}
36+
}
37+
\`\`\``;
38+
1139
// Sample AI response that demonstrates all markdown features
1240
const DEMO_MARKDOWN = `# NativeScript Streamdown 🚀
1341
@@ -38,18 +66,7 @@ export class DemoComponent {
3866
}
3967
\`\`\`
4068
41-
And here's some Swift for iOS:
42-
43-
\`\`\`swift
44-
import UIKit
45-
46-
class ViewController: UIViewController {
47-
override func viewDidLoad() {
48-
super.viewDidLoad()
49-
print("Hello from NativeScript!")
50-
}
51-
}
52-
\`\`\`
69+
${PLATFORM_CODE_EXAMPLE}
5370
5471
## Tables
5572

packages/nstreamdown/angular/components/md-code-block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare const android: any;
2525
@if (isIOS) {
2626
<Image [src]="copied() ? 'sys://checkmark.circle' : 'sys://document.on.document'" col="1" class="w-4 h-4 text-blue-400" (tap)="onCopy()"></Image>
2727
} @else {
28-
<label col="1" [text]="copied() ? 'Copied!' : 'Copy'" class="text-blue-400 font-medium px-2 mr-1" (tap)="onCopy()"></label>
28+
<Label col="1" [text]="copied() ? '' : '📋'" class="text-base text-blue-400 px-1" (tap)="onCopy()"></Label>
2929
}
3030
</GridLayout>
3131

packages/nstreamdown/lib/markdown-parser.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -357,43 +357,7 @@ export function parseInlineFormatting(text: string): MarkdownToken[] {
357357
});
358358
}
359359

360-
// Post-process: merge leading punctuation (and following space) from text tokens into preceding tokens
361-
// This prevents punctuation like commas from wrapping to a new line after links
362-
// Also merge the space after punctuation to keep text flowing naturally
363-
const LEADING_PUNCTUATION_AND_SPACE = /^([.,;:!?'")\]}>]+\s*)/;
364-
const mergedTokens: MarkdownToken[] = [];
365-
366-
for (let i = 0; i < tokens.length; i++) {
367-
const token = tokens[i];
368-
369-
if (token.type === 'text' && i > 0) {
370-
const prevToken = mergedTokens[mergedTokens.length - 1];
371-
const punctMatch = token.content.match(LEADING_PUNCTUATION_AND_SPACE);
372-
373-
if (punctMatch && prevToken && prevToken.type !== 'text') {
374-
// Merge the punctuation (and trailing space) with the previous token's content
375-
const punctuation = punctMatch[1];
376-
prevToken.content = prevToken.content + punctuation;
377-
prevToken.raw = prevToken.raw + punctuation;
378-
379-
// Update the text token to remove the merged punctuation
380-
const remainingContent = token.content.slice(punctuation.length);
381-
if (remainingContent.length > 0) {
382-
mergedTokens.push({
383-
type: 'text',
384-
raw: remainingContent,
385-
content: remainingContent,
386-
});
387-
}
388-
} else {
389-
mergedTokens.push(token);
390-
}
391-
} else {
392-
mergedTokens.push(token);
393-
}
394-
}
395-
396-
return mergedTokens.length > 0 ? mergedTokens : [{ type: 'text', raw: text, content: text }];
360+
return tokens.length > 0 ? tokens : [{ type: 'text', raw: text, content: text }];
397361
}
398362

399363
/**

0 commit comments

Comments
 (0)