forked from FINAKON/HelpProject
1. Initial Commit - a boiler plate code and POC to realize the concept of context sensitive help 2. Frontend code written in ReactJS 3. Backend code written in Java, Spring Boot Framework 4. Frontend Start: pre-requisites : node, npm npm run dev ==> to start the frontend vite server 5. Backend Start: pre-requisites : java, mvn mvn spring-boot:run ==> to start the backend server 6. Visit http://localhost:5173/ for basic demo of help, press F1 in textboxes 7. Visit http://localhost:5173/editor and enter "admin123" to add/modify texts. Happy Coding !!! Thank you, Bhargava.
54 lines
1.4 KiB
JavaScript
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
|
|
}
|