Pure, simple and elegant HTML parser and editor.

Related tags

Parsing html parser
Overview

Crates.io License

HTML Editor

Pure, simple and elegant HTML parser and editor.

Examples

Parse HTML segment/document

let document = parse("<!doctype html><html><head></head><body></body></html>");
println!("{:#?}", document);

Output:

[
    Doctype,
    Element {
        name: "html",
        attrs: {},
        children: [
            Element {
                name: "head",
                attrs: {},
                children: [],
            },
            Element {
                name: "body",
                attrs: {},
                children: [],
            },
        ],
    },
]

Query an element by classname

// let html = r#"..."#
let nodes = parse(html);
let selector: Selector = Selector::from(".last");
let element: Element = nodes.query(&selector).unwrap();

Query all elements by tag

// let html = r#"..."#
let nodes = parse(html);
let selector: Selector = Selector::from("span");
let elements: Vec<Element> = nodes.query_all(&selector);

Edit the HTML

// let html = r#"..."#
let a: String = parse(html).trim().html();
let b: String = parse(html).insert_to(&selector, node).html();
let c: String = parse(html).remove_by(&selector).html();

You can find more examples in the documentation.

Changelog

See in CHANGELOG.md

Comments
Releases(v0.5.2)
  • v0.5.2(Aug 21, 2022)

  • v0.5.1(Apr 27, 2022)

  • v0.5.0(Apr 15, 2022)

    Features

    • Add try_parse method for the html with tolerable errors by @lomirus in #2;
    • Add support for parsing xml doctype by @lomirus in #3;
    • Add associated Doctype variant to Node::Doctype to distinguish between html and xml by @lomirus.

    Refactor

    • Remove prelude module, and replace it with operation module by @lomirus, which also moves the Selector struct out of the original module to top of this package.

    Chore

    • Add benchmarking for the parse method by @lomirus, using an 87.0kB html file from wikipedia;

    Documentation

    • Readme and other documentation improvements by @lomirus.
    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Mar 19, 2022)

    v0.4.0 (2022-03-19)

    Fix

    • Fails to parse if closing tag is seperated by new-line, like<a></a\n>. Closes #1.

    Refactor

    • Add the prelude module. Now you can simply import Editable, Htmlifiable and Queryable all just by use html_editor::prelude::*;;
    • trim() method becomes (&mut self) -> &mut Self from (self) -> Self.
    • Replace the try_into_element() with into_element(), which simplifies the common use: try_into_element().unwrap()

    Documentation

    • Add more examples.
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Jan 29, 2022)

    Refactor

    • Now parse() returns a Result<Vec<Node>, String> instead of Vec<Node> for better error handling.

    Fix

    • In previous version, parse sometimes may return an unexpected result but without any error message. And now any currently known error will be delivered.
    • Tag string in <script> or <style> cannot be parsed correctly. For example, <script>"<div></div>"</script> would be parsed as a <div> element in the <script> instead of the plain string.
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Jan 19, 2022)

    Fix

    • Fail to parse the attributes if the the last key of it doesn't have the value, like <script src="index.js" type="module" defer></script>

    Enhancements

    • Omit the attribute if its value is empty. For example:

      <!--Old-->
      <script src="index.js" type="module" defer=""></script>
      
      <!--New-->
      <script src="index.js" type="module" defer></script>
      
    • Use vector to store the attributes instead of hashmap, which can make its order stable. For example:

      <!--Old. Maybe-->
      <script src="index.js" type="module"></script>
      <!--But it is also a possible result-->
      <script type="module" src="index.js"></script>
      
      <!--New. The result would be unique, and just the same as its input-->
      <script src="index.js" type="module"></script>
      
    Source code(tar.gz)
    Source code(zip)
Owner
Lomirus
Rookie Web Dev | Using TS/JS/RS | Wanna be an Indie Game Dev | Now just being slacking 😪
Lomirus
tiny md parser - md to html

tiny md parser md to html covered features lexer h1 h2 h3 list ( also numbered list ) code images links blockquote parser h1 h2 h3 list ( also numbere

jumango pussu 2 Dec 5, 2021
Yet Another Parser library for Rust. A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing strings and slices.

Yap: Yet another (rust) parsing library A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing input.

James Wilson 117 Dec 14, 2022
Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Microformats 5 Jul 19, 2022
WIP: Parse archived parler pages into structured html

parler-parse Parler HTML goes in (stdin), structured JSON comes out (stdout) Might be useful for feeding into elasticsearch or cross-referencing with

Christopher Tarquini 15 Feb 16, 2021
Rohanasantml an easy alternative to html!

Rohanasantml: An alternative to html An easy way to write your messy html code in a better way: html head title {Rohanasantml} title

Rohanasan 3 Mar 24, 2024
LR(1) grammar parser of simple expression

LR(1)语法分析程序 实验内容 编写LR(1)语法分析程序,实现对算术表达式的语法分析。要求所分析算数表达式由如下的文法产生: E -> E+T | E-T | T T -> T*F | T/F | F F -> (E) | num 程序设计与实现 使用方式:运行.\lr1-parser.exe

Gao Keyong 1 Nov 24, 2021
A native Rust port of Google's robots.txt parser and matcher C++ library.

robotstxt A native Rust port of Google's robots.txt parser and matcher C++ library. Native Rust port, no third-part crate dependency Zero unsafe code

Folyd 72 Dec 11, 2022
A rusty, dual-wielding Quake and Half-Life texture WAD parser.

Ogre   A rusty, dual-wielding Quake and Half-Life texture WAD parser ogre is a rust representation and nom parser for Quake and Half-Life WAD files. I

Josh Palmer 16 Dec 5, 2022
A modern dialogue executor and tree parser using YAML.

A modern dialogue executor and tree parser using YAML. This crate is for building(ex), importing/exporting(ex), and walking(ex) dialogue trees. convo

Spencer Imbleau 27 Aug 3, 2022
🕑 A personal git log and MacJournal output parser, written in rust.

?? git log and MacJournal export parser A personal project, written in rust. WORK IN PROGRESS; NOT READY This repo consolidates daily activity from tw

Steven Black 4 Aug 17, 2022
Sqllogictest parser and runner in Rust.

Sqllogictest-rs Sqllogictest parser and runner in Rust. License Licensed under either of Apache License, Version 2.0 (LICENSE-APACHE or http://www.apa

Singularity Data Inc. 101 Dec 21, 2022
Org mode structural parser/emitter with an emphasis on modularity and avoiding edits unrelated to changes.

Introduction Org mode structural parser/emitter with an emphasis on modularity and avoiding edits unrelated to changes. The goal of this library is to

Alex Roper 4 Oct 7, 2022
Parser for Object files define the geometry and other properties for objects in Wavefront's Advanced Visualizer.

format of the Rust library load locad blender obj file to Rust NDArray. cargo run test\t10k-images.idx3-ubyte A png file will be generated for the fi

Nasser Eddine Idirene 1 Jan 3, 2022
A CSS parser, transformer, and minifier written in Rust.

@parcel/css A CSS parser, transformer, and minifier written in Rust. Features Extremely fast – Parsing and minifying large files is completed in milli

Parcel 3.1k Jan 9, 2023
An IRC (RFC1459) parser and formatter, built in Rust.

ircparser An IRC (RFC1459) parser and formatter, built in Rust. ircparser should work on basically any Rust version, but the earliest version checked

Ethan Henderson 2 Oct 18, 2022
Lexer and parser collections.

laps Lexer and parser collections. With laps, you can build parsers by just defining ASTs and deriving Parse trait for them. Usage Add laps to your pr

MaxXing 11 Jan 27, 2023
A WIP svelte parser written in rust. Designed with error recovery and reporting in mind

Svelte(rs) A WIP parser for svelte files that is designed with error recovery and reporting in mind. This is mostly a toy project for now, with some v

James Birtles 3 Apr 19, 2023
Rust parser combinator framework

nom, eating data byte by byte nom is a parser combinators library written in Rust. Its goal is to provide tools to build safe parsers without compromi

Geoffroy Couprie 7.6k Jan 7, 2023
url parameter parser for rest filter inquiry

inquerest Inquerest can parse complex url query into a SQL abstract syntax tree. Example this url: /person?age=lt.42&(student=eq.true|gender=eq.'M')&

Jovansonlee Cesar 25 Nov 2, 2020