Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-schema-parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-schema-parser

A HTML parser based on schema

  • 0.1.1
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

http-schema-parser

Document

A HTML parser based on schema Reference source code https://github.com/caolan/pithy

Usage

npm install --save http-schema-parser
const HtmlSchemaParser = require('http-schema-parser')
const schema = [
  {
    tag: 'div',
    attribute: {
      style: 'background:#f0f0f0;'
    },
    content: [
      {
        tag: 'span',
        content: ['hello']
      },
      {
        tag: 'span',
        content: ['world']
      },
      {
        tag: 'ul',
        content: [
          {
            tag: 'li',
            content: ['item 001']
          },
          {
            tag: 'li',
            content: ['item 002']
          }
        ]
      }
    ],
  }
]

let scheamParser = new HtmlSchemaParser(schema);
let htmlStr = scheamParser.getHtml();

const $body = document.querySelector('body');
$body.innerHTML = htmlStr;

Instructions

schema propschema typeexample
tagString{"tag":"div"}
attributeObject{"attribute":{ "style":"background:#f0f0f0" }}
contentArray{ "content": ['hello', 'world', {"tag":"span", conent:['001']}, {"tag":"span", conent:['002']}] }

中文说明

基于schema格式的HTML解析器

参考源码自 https://github.com/caolan/pithy

使用方式

npm install --save http-schema-parser
const HtmlSchemaParser = require('http-schema-parser')
const schema = [
  {
    tag: 'div',
    attribute: {
      style: 'background:#f0f0f0;'
    },
    content: [
      {
        tag: 'span',
        content: ['hello']
      },
      {
        tag: 'span',
        content: ['world']
      },
      {
        tag: 'ul',
        content: [
          {
            tag: 'li',
            content: ['item 001']
          },
          {
            tag: 'li',
            content: ['item 002']
          }
        ]
      }
    ],
  }
]

let scheamParser = new HtmlSchemaParser(schema);
let htmlStr = scheamParser.getHtml();

const $body = document.querySelector('body');
$body.innerHTML = htmlStr;

说明

schema属性schema类型例子
tagString{"tag":"div"}
attributeObject{"attribute":{ "style":"background:#f0f0f0" }}
contentArray{ "content": ['hello', 'world', {"tag":"span", conent:['001']}, {"tag":"span", conent:['002']}] }

FAQs

Package last updated on 03 Jun 2018

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc