GithubHelp home page GithubHelp logo

lbstanza-tidy's Introduction

Stanza wrapper for LibTidy

This adds a stanza wrapper around the libtidy implementation. This allows for parsing HTML, XHTML, and XML documents.

Setup

This module includes tidy-html5 as a git submodule for ease of build.

sudo apt install cmake build-essentials
git submodule update --init
cd tidy-html5
mkdir output
cd output
cmake ..
make

This will place the static/dynamic artifacts in the tidy-html5/output directory. The start.sh script references this directory and the tidy-html5/include folder.

If you want to install libtidy using your OS's package manager, you will need to set the environment variables in start.sh to the correct location to find the headers and libraries.

Build

$> source start.sh
$> make tests
stanza build
stanza build tidy-tests
./tidy-tests
[Test 1] test-basic
[PASS]

[Test 2] test-child-parent
[PASS]

[Test 3] test-node-attr
[PASS]

[Test 4] test-node-text
[PASS]

[Test 5] test-node-seq
[PASS]

[Test 6] test-attr-seq
[PASS]

[Test 7] test-version-basic
Release Date: 2022/01/25
Version : 5.9.20
Platform : Linux
[PASS]

Tests Finished: 7/7 tests passed. 0 tests skipped. 0 tests failed.

Longest Running Tests:
[PASS] test-basic (730 us)
[PASS] test-version-basic (515 us)
[PASS] test-attr-seq (371 us)
[PASS] test-node-text (340 us)
[PASS] test-node-seq (319 us)
[PASS] test-child-parent (297 us)
[PASS] test-node-attr (271 us)

Example

  val doc = TidyDoc()
  val stat = get-status(doc)
  #EXPECT(stat == 0)

  val input = "<!DOCTYPE html><html><head><title>SomeStuff</title></head><body><p id=\"asdf\">SomeText</p><p id=\"qwer\">SomeMoreText</p></body></html>"

  val code = parse-str(doc, input)
  #EXPECT(code == 0)

  val body = get-body(doc)
  val pElems = to-tuple(get-children(body))
  ; pElems = [TidyNode(...), TidyNode(...)]
  ;   Where the pElems are the two 'p' nodes in the body.

See the unit tests for some more examples.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.