15.2.3 • Published 7 months ago

@fsegurai/marked-extended-typographic v15.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

A library of extended typographic features for Marked.js.

@fsegurai/marked-extended-typographic is an extension for Marked.js that adds support for extended typographic characters to easily translate plain ASCII punctuation characters into "smart" typographic punctuation HTML entities.

Table of contents

Installation

To add @fsegurai/marked-extended-typographic along with Marked.js to your package.json use the following commands.

bun install @fsegurai/marked-extended-typographic marked@^15.0.0 --save

Usage

Basic Usage

Import @fsegurai/marked-extended-typographic and apply it to your Marked instance as shown below.

import { marked } from "marked";
import markedExtendedTypographic from "@fsegurai/marked-extended-typographic";

// or UMD script
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
// <script src="https://cdn.jsdelivr.net/npm/@fsegurai/marked-extended-typographic/lib/index.umd.js"></script>

marked.use(markedExtendedTypographic());

const exampleMarkdown = `
He said, -- \"A 'simple' sentence. . .\" --- unknown

(omega) - (alpha) - (beta)

Copyright (C^) 2024. All rights reserved.
`;

marked.parse(exampleMarkdown);

Configuration Options

You can customize the typographic behavior with several options:

// Default behavior (recommended)
marked.use(markedExtendedTypographic());

// With specific configuration
marked.use(
    markedExtendedTypographic({
        quotes: true, // Enable smart quotes (default: true)
        dashes: true, // Enable smart dashes (default: true)
        ellipses: true, // Enable smart ellipses (default: true)
        attribute: "2", // Typographic style attribute (default: '2')
        outputUnicode: true, // Output Unicode characters instead of HTML entities (default: false)
        customSymbols: {
            // Add custom symbol replacements
            "\\(lambda\\)": "λ",
            "\\(tm\\)": "™",
        },
    }),
);
  • attribute: Specifies the typographic style attribute. The default is 2, which uses the lang attribute for language-specific typographic styles.
    • 0 Disables typographic styles.
    • 1 Enable quotes, backticks, dashes and ellipses
    • 2 Same as '1' but with old-school dash behavior (-- for en-dash, --- for em-dash)
    • 3 Same as '1' but with inverted old-school dash behavior (-- for em-dash, --- for en-dash)
    • -1 Special "stupefy" mode that converts typographic characters back to ASCII

Symbol References

The marked-extended-typographic extension supports a wide variety of special symbols that can be added to your markdown using simple text patterns.

Special Characters

MarkdownSymbolDescription
(<<)«Left-pointing double angle quotation mark
(>>)»Right-pointing double angle quotation mark
(<-)Left arrow
(->)Right arrow
(<->)Left-right arrow
(<=>)Double arrow left-right
(<==>)Left double arrow
(=>)Implies/right double arrow
(<==)Left double arrow
(==>)Right double arrow
(==)Identical to
(<)Much less than
(>)Much greater than
(<=)Less than or equal to
(>=)Greater than or equal to
(<>)Neither less than nor greater than
(><)Neither greater than nor less than
(+-)±Plus-minus sign
(-+)Minus-plus sign
(x)×Multiplication sign
(/)÷Division sign
(=>)Right double arrow
(<=)Left double arrow
(^up)Up arrow
(^down)Down arrow
(^left)Left arrow
(^right)Right arrow
(^updown)Up-down arrow
(^leftright)Left-right arrow
(--)Em dash
(---)En dash

Logical and Mathematical Symbols

MarkdownSymbolDescription
(+)Direct sum
(-)Direct difference
(*)Tensor product
(\|)Divides
(&)Logical and
(\|\|)Logical or
(!)¬Logical not
(=)Not equal
(~)Approximately equal
(^)Logical and
(%)Per mille
(#)Numero sign
(@)Circled plus
($)¤Currency sign
(sum)Summation symbol
(prod)Product symbol
(sqrt)Square root symbol
(cbrt)Cube root symbol
(inf)Infinity symbol
(integral)Integral symbol
(partial)Partial derivative
(empty)Empty set symbol
(in)Element of
(notin)Not an element of
(subset)Subset of
(subseteq)Subset or equal to
(nsubset)Not a subset of
(nsubseteq)Not a subset or equal to
(superset)Superset of
(nsuperset)Not a superset of
(union)Union symbol
(intersection)Intersection symbol
(forall)For all
(exists)There exists
(nexists)There does not exist

Typographic Symbols

MarkdownSymbolDescription
(C^) or (c^)©Copyright
(R^) or (r^)®Registered trademark
(TM^) or (tm^)Trademark
(P^) or (p^)Sound recording copyright
(S^) or (s^)§Section
(D^) or (d^)Dagger
(DD^) or (dd^)Double dagger
(P*) or (p*)Paragraph
(euro)Euro
(pound)£Pound sterling
(yen)¥Yen
(cent)¢Cent
(colon)Colon
(degree)°Degree
(micro)µMicro sign
(middledot)Middle dot
(bullet)Bullet
(nbsp)Non-breaking space
(endash)En dash
(emdash)Em dash

Greek Letters

MarkdownSymbolMarkdownSymbol
(alpha) or (Alpha)α(nu) or (Nu)ν
(beta) or (Beta)β(xi) or (Xi)ξ
(gamma) or (Gamma)γ(omicron) or (Omicron)ο
(delta) or (Delta)δ(pi) or (Pi)π
(epsilon) or (Epsilon)ε(rho) or (Rho)ρ
(zeta) or (Zeta)ζ(sigma) or (Sigma)σ
(eta) or (Eta)η(tau) or (Tau)τ
(theta) or (Theta)θ(upsilon) or (Upsilon)υ
(iota) or (Iota)ι(phi) or (Phi)φ
(kappa) or (Kappa)κ(chi) or (Chi)χ
(lambda) or (Lambda)λ(psi) or (Psi)ψ
(mu) or (Mu)μ(omega) or (Omega)ω
(nabla) or (Nabla)(theta) or (Theta)θ

Emoji Symbols

Emoji Symbols

MarkdownSymbolDescription
(check)Check mark
(cross)Cross mark
(warning)⚠️Warning sign
(info)ℹ️Information symbol
(star)Black star
(phone)☎️Telephone symbol
(mail)✉️Envelope
(music)🎵Musical note
(sunny)☀️Sun
(cloud)☁️Cloud
(umbrella)☂️Umbrella
(snowflake)❄️Snowflake
(recycle)♻️Recycling symbol
(heart)❤️Heart
(brokenheart)💔Broken heart
(fire)🔥Fire
(water)💧Water droplet
(flag)🚩Flag
(thumbsup)👍Thumbs up sign
(thumbsdown)👎Thumbs down sign
(clap)👏Clapping hands
(wave)👋Waving hand
(smile)😊Smiling face
(sad)😢Crying face
(angry)😠Angry face
(laugh)😂Laughing face
(wink)😉Winking face
(kiss)😘Kissing face
(surprised)😲Surprised face
(clock)🕒Clock face
(calendar)📅Calendar
(gear)Gear
(link)🔗Link symbol
(lock)🔒Lock
(unlock)🔓Unlock

Available Extensions

ExtensionPackageVersionDescription
Accordion@fsegurai/marked-extended-accordionnpmAdd collapsible accordion sections to your markdown
Alert@fsegurai/marked-extended-alertnpmCreate styled alert boxes for important information
Footnote@fsegurai/marked-extended-footnotenpmAdd footnotes with automatic numbering
Lists@fsegurai/marked-extended-listsnpmEnhanced list formatting options
Spoiler@fsegurai/marked-extended-spoilernpmHide content behind spoiler tags
Tables@fsegurai/marked-extended-tablesnpmAdvanced table formatting with cell spanning
Tabs@fsegurai/marked-extended-tabsnpmCreate tabbed content sections
Timeline@fsegurai/marked-extended-timelinenpmDisplay content in an interactive timeline format
Typographic@fsegurai/marked-extended-typographicnpmImprove typography with smart quotes, dashes, and more

Demo Application

To see all extensions in action, check out the [DEMO].

To set up the demo locally, follow the next steps:

git clone https://github.com/fsegurai/marked-extensions.git
bun install
bun start

This will serve the application locally at http://[::1]:8000.

License

Licensed under MIT.