0.8.5 • Published 2 years ago

@writewithocto/ink v0.8.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

latest tag license open issues

Ink

The flexible TypeScript Markdown editor that powers https://octo.app.

npm.io

Install

npm install --save @writewithocto/ink

Usage

Minimal Configuration

Create a basic editor without worrying about state.

import ink from '@writewithocto/ink'

ink(document.getElementById('editor'))

State Tracking

Supply some initial data and set a callback to track data changes.

import ink from '@writewithocto/ink'

ink(document.getElementById('editor'), {
  doc: '# Start with some text',
  onChange: (doc) => {
    console.log('Doc edited:', doc)
  },
})

Hot-swap Docs

Swap the active doc without rebuilding the whole DOM or re-supplying configuration.

import ink from '@writewithocto/ink'

const editor = ink(document.getElementById('editor'))

// user performs some action to change the active doc...
editor.load('# New Doc')

Customization

Fonts

The fonts for @writewithocto/ink can be customized with CSS variables.

CSS VariableDescriptionDefault Value
--ink-font-familyProportional font used for normal textsans-serif
--ink-font-family-monoMonospace font used for codemonospace

Images

When the renderImages: true config is used, some image properties can be changed with CSS variables.

CSS VariableDescriptionDefault Value (Dark)Default Value (Light)
--ink-image-background-colorBackground color for image containersrgba(0, 0, 0, 0.2)rgba(0, 0, 0, 0.05)
--ink-image-border-radiusBorder radius for image containers0.25rem0.25rem
--ink-image-max-heightMax height for images20rem20rem

Code / Code Blocks

CSS VariableDescriptionDefault Value (Dark)Default Value (Light)
--ink-code-background-colorBackground color for inline codergba(0, 0, 0, 0.2)rgba(0, 0, 0, 0.05)
--ink-code-border-radiusBorder radius for inline code0.25rem0.25rem
--ink-code-paddingPadding for inline code0.125rem0.125rem
--ink-codeblock-background-colorBackground color for code blocksrgba(0, 0, 0, 0.2)rgba(0, 0, 0, 0.05)
--ink-codeblock-border-radiusBorder radius for code blocks0.25rem0.25rem
--ink-codeblock-paddingPadding for code blocks0.5rem0.5rem

Syntax Highlighting

The syntax highlighting theme is fully configurable through CSS variables. This means we can do things like...

  • Change the heading colors
  • Change all (or some) colors for individual light and dark modes
  • Make adjustments for accessibility

Check out the examples below.

Examples

Light and Dark modes

Make headings dark for light mode and light for dark mode.

.light {
  --ink-heading: #111;
}

.dark {
  --ink-heading: #eee;
}

Tags / CSS Variable Reference

Tags are applied to the code by the CodeMirror language parsers. This means things could possibly be a bit off depending on the language being highlighted. If you think something is being incorrectly highlighted, feel free to open an issue. The CSS variables listed under a given Tag are in order of highest-to-lowest precedence. For more information about Tags, check out the CodeMirror Tag reference.

TagCSS VariableCSS PropertyDefault Value
atom--ink-atomcolor#d19a66
meta--ink-metacolor#abb2bf
processingInstruction--ink-processingInstructioncolor#abb2bf
comment--ink-commentcolor#abb2bf
name--ink-namecolor#d19a66
labelName--ink-labelName--ink-namecolor#abb2bf
propertyName--ink-propertyName--ink-namecolor#96c0d8
propertyName (definition)--ink-propertyName-definition--ink-propertyName--ink-namecolor#e06c75
variableName--ink-variableName--ink-namecolor#e06c75
variableName (definition)--ink-variableName-definition--ink-variableName--ink-namecolor#e5c07b
variableName (local)--ink-variableName-local--ink-variableName--ink-namecolor#d19a66
variableName (special)--ink-variableName-special--ink-variableName--ink-namecolorinherit
heading--ink-headingcolor#e06c75
heading--ink-heading-weightfont-weight600
heading1--ink-heading1--ink-headingcolor#e06c75
heading1--ink-heading1-weight--ink-heading-weightfont-weight600
heading2--ink-heading2--ink-headingcolor#e06c75
heading2--ink-heading2-weight--ink-heading-weightfont-weight600
heading3--ink-heading3--ink-headingcolor#e06c75
heading3--ink-heading3-weight--ink-heading-weightfont-weight600
heading4--ink-heading4--ink-headingcolor#e06c75
heading4--ink-heading4-weight--ink-heading-weightfont-weight600
heading5--ink-heading5--ink-headingcolor#e06c75
heading5--ink-heading5-weight--ink-heading-weightfont-weight600
heading6--ink-heading6--ink-headingcolor#e06c75
heading6--ink-heading6-weight--ink-heading-weightfont-weight600
keyword--ink-keywordcolor#c678dd
number--ink-numbercolor#d19a66
operator--ink-operatorcolor#96c0d8
punctuation--ink-punctuationcolor#36454f
link--ink-linkcolor#96c0d8
url--ink-urlcolor#96c0d8
string--ink-stringcolor#98c379
string (special)--ink-string-special--ink-stringcolorinherit
emphasis--ink-emphasiscolorinherit
strikethrough--ink-strikethroughcolorinherit
strong--ink-strongcolorinherit
strong--ink-strong-weightfont-weight600

Support

Your support is appreciated. Here are some ways you can help. ♥️

Leave the Attribution enabled

There is a small Powered by Ink attribution in the bottom-right corner of all Ink instances by default. Ink is a free MIT-licensed library under independent development, and that attribution helps to increase awareness of this project.

Provide Feedback

Your feedback is immensely important for building Ink into a library that we all love. Consider starting a discussion under Octo if you have a question or just want to chat about ideas!

Open a Pull Request

If you feel comfortable tackling an existing issue, please consider opening a Pull Request! I am happy to introduce you to the codebase and work with you to get it merged!

Donate

Donations help support the development of Ink.

0.8.5

2 years ago

0.6.7

2 years ago

0.8.4

2 years ago

0.6.6

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.8.1

2 years ago

0.6.3

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.6.2

2 years ago

0.8.3

2 years ago

0.6.5

2 years ago

0.8.2

2 years ago

0.6.4

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.2

2 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago