Skip to content

Commit

Permalink
Support rendering smartypants
Browse files Browse the repository at this point in the history
  • Loading branch information
dtonon committed Jul 9, 2024
1 parent 8f5adac commit 0b098c2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 37 deletions.
18 changes: 9 additions & 9 deletions dist/index.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions examples/fiatjaf.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions examples/hodlbod.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions examples/opensats.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Note.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { getConfig } from './config';
import { documentTitle } from './stores/documentTitleStore';
import { getEventData, processUsersEntities, processEventsEntities, processImageUrls, processVideoUrls, formatDate } from './utils';
import { getEventData, processUsersEntities, processEventsEntities, processImageUrls, processVideoUrls, processSmartyPants, formatDate } from './utils';
import { pool } from './stores/websocket';
import showdown from 'showdown';
import * as nip19 from 'nostr-tools/nip19'
Expand Down Expand Up @@ -60,6 +60,7 @@
note_content = processEventsEntities(note_content);
note_content = processImageUrls(note_content)
note_content = processVideoUrls(note_content)
note_content = processSmartyPants(note_content)
// Render returns in kind:1
if (event.kind == 1) {
Expand Down
16 changes: 16 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ export function processVideoUrls(text) {
return htmlText;
}

export function processSmartyPants(text){
const replacements = [
{ regex: /<<|»/g, replacement: '&laquo;' },
{ regex: />>|«/g, replacement: '&raquo;' },
{ regex: /\.\.\./g, replacement: '&hellip;' },
{ regex: /---/g, replacement: '&mdash;' },
{ regex: /--/g, replacement: '&mdash;' },
];

replacements.forEach(({ regex, replacement }) => {
text = text.replace(regex, replacement);
});

return text;
}


export function formatDate(timestamp, includeTime = false) {
const date = new Date(timestamp * 1000);
Expand Down

0 comments on commit 0b098c2

Please sign in to comment.