You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

pug-lexer

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pug-lexer

The jade lexer (takes a string and converts it to an array of tokens)


Version published
Maintainers
1
Created

Package description

What is pug-lexer?

The pug-lexer npm package is a lexer for the Pug templating language. It tokenizes Pug source code into a stream of tokens that can be used for further processing, such as parsing or compiling into HTML.

What are pug-lexer's main functionalities?

Tokenizing Pug Source Code

This feature allows you to tokenize Pug source code. The code sample demonstrates how to use the pug-lexer to convert a simple Pug template into a stream of tokens.

const lexer = require('pug-lexer');
const tokens = lexer('p
  | Hello, World!');
console.log(tokens);

Handling Indentation

This feature handles the indentation in Pug templates. The code sample shows how nested elements are tokenized, preserving the hierarchical structure.

const lexer = require('pug-lexer');
const tokens = lexer('div
  p Hello
    span World');
console.log(tokens);

Custom Filters

This feature supports custom filters in Pug templates. The code sample demonstrates how a custom filter like 'markdown' is tokenized.

const lexer = require('pug-lexer');
const tokens = lexer('p: markdown
  **Hello, World!**');
console.log(tokens);

Other packages similar to pug-lexer

Readme

Source

jade-lexer

The jade lexer. This module is responsible for taking a string and converting it into an array of tokens.

Build Status Dependency Status NPM version

Installation

npm install jade-lexer

Usage

var lex = require('jade-lexer');

lex(str, filename, options)

Convert Jade string to an array of tokens.

filename, if provided, is used in error handling.

options can contain the following property:

  • plugins (array): An array of plugins, in the order they should be applied.
console.log(JSON.stringify(lex('div(data-foo="bar")', 'my-file.jade'), null, '  '))
[
  {
    "type": "tag",
    "line": 1,
    "val": "div",
    "selfClosing": false
  },
  {
    "type": "attrs",
    "line": 1,
    "attrs": [
      {
        "name": "data-foo",
        "val": "\"bar\"",
        "escaped": true
      }
    ]
  },
  {
    "type": "eos",
    "line": 1
  }
]

new lex.Lexer(str, filename, options)

Constructor for a Lexer class. This is not meant to be used directly unless you know what you are doing.

options may contain the following properties:

  • interpolated (boolean): if the Lexer is created as a child lexer for inline tag interpolation (e.g. #[p Hello]). Defaults to false.
  • startingLine (integer): the real line number of the first line in the input. It is also used for inline tag interpolation. Defaults to 1.
  • plugins (array): An array of plugins, in the order they should be applied.

License

MIT

Keywords

FAQs

Package last updated on 11 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc