Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

talk-lexer

project9MIT0.1.23

lexer ===

readme

lexer

Rich text lexer for teambition projects

Whitelist

  • plain text
  • mention

Example

data = [{type: 'mention', text: "@user", data: {id: '1'}}, ", Hello"]

# data to html
lexer(data).html()  ==>  '<mention data-id="1">@user</mention>, Hello'

# data to text
lexer(data).text()  ==>  '@user, Hello'

# parseDOM
input = document.getElementById('input')
lex = lexer.parseDOM(input.childNodes)
lex.html()  ==>  '<mention data-id="1">@user</mention>, Hello'
lex.text()  ==>  '@user, Hello'

# parseDOM with options
## lexer will grep the matched username and transfer to a mention tag
lex = lexer.parseDOM(input.childNodes, mention: [{match: 'Grace', data: id: '1'}])

# validate the data
lexer({type: 'mention'}).isValid()  ==>  true

TODO

Types

# text
['hello world']
==> hello world

# mention
[{type: 'mention', text: '@user', data: id: '1'}]
==> <mention data-id="1">@user</mention>

# link
[{type: 'link', text: 'Teambition', href: 'https://www.teambition.com'}]
==> <a href="https://www.teambition.com" class="lexer-link" rel="noreferrer" target="_blank">Teambition</a>

# highlight
[{type: 'highlight', text: 'I am blue'}]
==> <em class="lexer-highlight">I am blue</em>

LICENSE

MIT

changelog

0.1.11

  • trim the \n and whitespace in the end of string

0.1.9

  • parse <br> and <div> to \n in parseDOM method
  • replace \n with <br> in html method

0.1.6

  • add highlight type

0.1.5

  • convert html tags to entities when using html() function

0.1.1

  • add createElement function

0.1.0

  • add link in whitelist