minihtml 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3344f1746e177e0685a421dca8e443dd0d2c3770d0b8188a3d9eb77fbab8a798
4
+ data.tar.gz: fb0ed43e289e84449ef1636cc38f40e8f250884bec09188d66918fd8150a2500
5
+ SHA512:
6
+ metadata.gz: 6376d8f7355ccfd408803f11f092915c75ac49849439aafc7e952e386dbbcd3c42f2456295b0bf7a431bfa05ec5f728eef2d079cdfa7ebe4297feda66f2a3fc2
7
+ data.tar.gz: 96912dc65721e26e920a3a1679aa154f0b8c82814f923e933b4eb71c47fb3198ff90bc7459b1fe85b4a197695be36563afb99c698f29af55c494ae7435b45de7
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_size = 2
7
+ indent_style = space
8
+ insert_final_newline = true
9
+ tab_width = 2
10
+ trim_trailing_whitespace = true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,73 @@
1
+ plugins: rubocop-performance
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 3.4
5
+ NewCops: enable
6
+ SuggestExtensions: false
7
+ Exclude:
8
+ - spec/parsing_tests/*
9
+ - vendor/**/*
10
+ - benchmarks/**/*
11
+
12
+ Style/StringLiterals:
13
+ EnforcedStyle: double_quotes
14
+
15
+ Style/StringLiteralsInInterpolation:
16
+ EnforcedStyle: double_quotes
17
+
18
+ Metrics/CyclomaticComplexity:
19
+ Enabled: false
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: false
23
+
24
+ Metrics/PerceivedComplexity:
25
+ Enabled: false
26
+
27
+ Metrics/MethodLength:
28
+ Enabled: false
29
+
30
+ Metrics/AbcSize:
31
+ Enabled: false
32
+
33
+ Lint/MixedRegexpCaptureTypes:
34
+ Enabled: false
35
+
36
+ Layout/LineLength:
37
+ Enabled: false
38
+
39
+ Style/Documentation:
40
+ Enabled: false
41
+
42
+ Metrics/ModuleLength:
43
+ Enabled: false
44
+
45
+ Metrics/ClassLength:
46
+ Enabled: false
47
+
48
+ Layout/CaseIndentation:
49
+ EnforcedStyle: end
50
+
51
+ Layout/MultilineOperationIndentation:
52
+ EnforcedStyle: indented
53
+
54
+ Layout/SpaceAroundOperators:
55
+ EnforcedStyleForExponentOperator: space
56
+
57
+ Layout/EndAlignment:
58
+ EnforcedStyleAlignWith: start_of_line
59
+
60
+ Style/SignalException:
61
+ Exclude:
62
+ - spec/**/*
63
+
64
+ Naming/PredicateMethod:
65
+ Exclude:
66
+ - lib/minicss/css/parser.rb
67
+
68
+ Lint/HashCompareByIdentity:
69
+ Exclude:
70
+ - lib/minicss/sel.rb
71
+
72
+ Layout/FirstHashElementIndentation:
73
+ EnforcedStyle: consistent
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.5
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ hey@vito.io.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Vito Sartori
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # MiniHTML
2
+
3
+ MiniHTML is a tiny HTML tokenizer and parser with a JSX-inspired syntax. It is designed to power template-like inputs that mix static markup with executable expressions, returning a small, Ruby-friendly abstract syntax tree (AST).
4
+
5
+ ## Features
6
+
7
+ - Understands standard HTML tags plus component-style names such as `Foo::Bar`.
8
+ - Supports self-closing tags (`<Tag />`) and nested child nodes.
9
+ - Handles attributes without values as well as string, literal, or executable (`{{ expr }}`) attribute values.
10
+ - Preserves plain text nodes, comment nodes (`<!-- ... -->`), and boolean attributes.
11
+ - Provides string interpolation inside quoted values (`title="Hello {{name}}"`).
12
+ - Produces rich AST nodes (`MiniHTML::AST::Tag`, `PlainText`, `String`, `Literal`, `Executable`, `Interpolation`, `Comment`, `Attr`) that include source locations.
13
+ - Raises descriptive errors for unterminated strings, comments, or interpolation blocks during tokenization.
14
+
15
+ ## Installation
16
+
17
+ This project ships as a Ruby gem with native extensions and requires Ruby 3.4 or newer.
18
+
19
+ Add it to your `Gemfile` directly from GitHub until it is published to RubyGems:
20
+
21
+ ```ruby
22
+ gem "minihtml"
23
+ ```
24
+
25
+ Then install the dependencies:
26
+
27
+ ```bash
28
+ bundle install
29
+ ```
30
+
31
+ The extensions use the standard Ruby build toolchain (`extconf.rb`); make sure a compiler and headers are available on your system.
32
+
33
+ ## Usage
34
+
35
+ ### Parsing markup into an AST
36
+
37
+ ```ruby
38
+ require "minihtml"
39
+
40
+ source = <<~HTML
41
+ <header id="greeting" data-count={{items.size}}>
42
+ Hello {{user.name}}!
43
+ <Button disabled />
44
+ <Link href="/users/{{user.id}}">View profile</Link>
45
+ </header>
46
+ HTML
47
+
48
+ parser = MiniHTML::Parser.new(source)
49
+ ast = parser.parse
50
+
51
+ ast.first # => #<MiniHTML::AST::Tag name="header" ...>
52
+ ```
53
+
54
+ Every node carries positional metadata so you can map AST entries back to their origin in the source string.
55
+
56
+ ### Working with tokens directly
57
+
58
+ If you only need lexical analysis, you can use the scanner extension on its own:
59
+
60
+ ```ruby
61
+ scanner = MiniHTML::Scanner.new("<div title=\"Hello {{name}}\">")
62
+ tokens = scanner.tokenize
63
+
64
+ # => [{ kind: :tag_begin, literal: "<div" }, ...]
65
+ scanner.errors # => []
66
+ ```
67
+
68
+ Errors gathered during scanning are exposed through `scanner.errors`. The parser raises `MiniHTML::ParseError` when scanning fails, wrapping the collected messages.
69
+
70
+ ## Supported syntax and limitations
71
+
72
+ - Tag names must start with a letter. Subsequent characters may include digits, underscores, colons, or dots. Hyphenated component names (e.g. `<my-component>`) are not recognised.
73
+ - Attribute names must begin with a letter and may contain digits, dashes, underscores, or dots. Unquoted attribute values are limited to identifier characters (`[A-Za-z0-9_:.]`).
74
+ - Executable sections are delimited by `{{` and `}}`. Nested braces inside the executable body are balanced correctly, but unmatched blocks trigger an error.
75
+ - Interpolation inside strings reuses executable parsing; escaped quotes (`\"`) are preserved in the resulting `AST::String` literal.
76
+ - HTML entities are not decoded; the parser leaves them exactly as written.
77
+ - Doctype declarations, script/style parsing nuances, and malformed HTML recovery are out of scope.
78
+
79
+ ## Development
80
+
81
+ ```bash
82
+ bin/setup # install dependencies
83
+ bundle exec rake
84
+ ```
85
+
86
+ Both the scanner and token stream extensions live under `ext/`; rerun `bundle exec rake compile` after making changes to the C sources.
87
+
88
+ ## License
89
+
90
+ ```
91
+ The MIT License (MIT)
92
+
93
+ Copyright (c) 2025 Vito Sartori
94
+
95
+ Permission is hereby granted, free of charge, to any person obtaining a copy
96
+ of this software and associated documentation files (the "Software"), to deal
97
+ in the Software without restriction, including without limitation the rights
98
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
+ copies of the Software, and to permit persons to whom the Software is
100
+ furnished to do so, subject to the following conditions:
101
+
102
+ The above copyright notice and this permission notice shall be included in
103
+ all copies or substantial portions of the Software.
104
+
105
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
111
+ THE SOFTWARE.
112
+ ```
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ require "rake/extensiontask"
13
+
14
+ task build: :compile
15
+
16
+ GEMSPEC = Gem::Specification.load("minihtml.gemspec")
17
+
18
+ Rake::ExtensionTask.new("minihtml_scanner", GEMSPEC) do |ext|
19
+ ext.lib_dir = "lib/minihtml"
20
+ end
21
+
22
+ Rake::ExtensionTask.new("minihtml_token_stream", GEMSPEC) do |ext|
23
+ ext.lib_dir = "lib/minihtml"
24
+ end
25
+
26
+ task default: %i[clobber compile spec rubocop]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ append_cflags("-fvisibility=hidden")
6
+
7
+ create_makefile("minihtml/minihtml_scanner")