Files
boris/node_modules/micromark-util-decode-string/dev/index.js
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

54 lines
1.4 KiB
JavaScript

import {decodeNamedCharacterReference} from 'decode-named-character-reference'
import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'
import {codes, constants} from 'micromark-util-symbol'
const characterEscapeOrReference =
/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi
/**
* Decode markdown strings (which occur in places such as fenced code info
* strings, destinations, labels, and titles).
*
* The “string” content type allows character escapes and -references.
* This decodes those.
*
* @param {string} value
* Value to decode.
* @returns {string}
* Decoded value.
*/
export function decodeString(value) {
return value.replace(characterEscapeOrReference, decode)
}
/**
* @param {string} $0
* Match.
* @param {string} $1
* Character escape.
* @param {string} $2
* Character reference.
* @returns {string}
* Decoded value
*/
function decode($0, $1, $2) {
if ($1) {
// Escape.
return $1
}
// Reference.
const head = $2.charCodeAt(0)
if (head === codes.numberSign) {
const head = $2.charCodeAt(1)
const hex = head === codes.lowercaseX || head === codes.uppercaseX
return decodeNumericCharacterReference(
$2.slice(hex ? 2 : 1),
hex ? constants.numericBaseHexadecimal : constants.numericBaseDecimal
)
}
return decodeNamedCharacterReference($2) || $0
}