
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
@sojs_coder/htmlc
Advanced tools
A high-performance Node.js library for parsing and processing HTML components with support for templating, conditional rendering, loops, and nested components.
npm install @sojs_coder/htmlc -g
project/
āāā components/
ā āāā header.html
ā āāā footer.html
ā āāā nav/
ā āāā menu.html
āāā pages/
ā āāā index.html
<!-- components/header.html -->
<header>
<h1>{{title}}</h1>
{% if (showSubtitle) %}
<h2>{{subtitle}}</h2>
{% endif %}
</header>
<!-- components/nav/menu.html -->
<nav>
<ul>
{% for item in menuItems %}
<li>{{item}}</li>
{% endfor %}
</ul>
</nav>
<!-- pages/index.html -->
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<header title="Welcome" showSubtitle="true" subtitle="Hello World" />
<nav/menu menuItems="Home,About,Contact" />
</body>
</html>
const ComponentParser = require('@sojs_coder/htmlc');
const parser = new ComponentParser('pages');
parser.processDirectory();
The library can be used from the command line:
# Basic usage
htmlc pages
# With options
htmlc pages --depth=2 --names=header,footer --out=dist --logs
--depth=<n>
: Set maximum directory depth for parsing--names=a,b,...
: Specify specific component names to process--out=<path>
: Specify output directory--logs
: Enable debug logging--minify
: Do you want to minify files or not?--toMinify=a,b
: What file extensions to minify (defaults to html if --minify is enabled. Will not work without --minify)help
: Show help informationconst parser = new ComponentParser(directory, options);
{
depth: number, // Maximum directory depth (default: Infinity)
names: string[], // Specific component names to process
out: string, // Output directory path
logs: boolean // Enable debug logging
minify: boolean // Enable minification
toMinify: string[] // File extensions to minify (if minify is enabled). Defaults to ["html"]
}
<componentName prop1="value1" prop2="value2" />
{% if (condition) %}
Content to show if condition is true
{% endif %}
{% if (condition1) %}
Content for condition1
{% elif (condition2) %}
Content for condition2
{% else %}
Default content
{% endif %}
{% for item in items %}
<div>{{item}}</div>
{% endfor %}
<!-- components/card.html -->
<div class="card">
<header title="{{title}}" showSubtitle="{{showSubtitle}}" subtitle="{{subtitle}}" />
<div class="card-content">
{{content}}
</div>
<footer copyright="{{copyright}}" />
</div>
<!-- Usage -->
<card
title="My Card"
showSubtitle="true"
subtitle="Card Subtitle"
content="Card content goes here"
copyright="2024"
/>
<!-- components/userList.html -->
<div class="user-list">
{% if (hasUsers) %}
{% for user in users %}
<div class="user-card">
<h3>{{user}}</h3>
{% if (showEmail) %}
<email address="{{user}}@example.com" />
{% endif %}
</div>
{% endfor %}
{% else %}
<p>No users found</p>
{% endif %}
</div>
<!-- Usage -->
<userList
hasUsers="true"
users="John,Jane,Bob"
showEmail="true"
/>
const ComponentParser = require('component-parser');
async function buildWebsite() {
const parser = new ComponentParser('src', {
depth: 3,
names: ['header', 'footer', 'nav'],
out: 'dist',
logs: true
});
try {
await parser.processDirectory();
console.log('Website built successfully!');
} catch (error) {
console.error('Build failed:', error);
}
}
buildWebsite();
Template Caching
Parallel Processing
Selective Processing
names
option to process only specific componentsdepth
to limit directory recursionThe library throws descriptive errors for common issues:
try {
await parser.processDirectory();
} catch (error) {
if (error.message.includes('Components directory not found')) {
// Handle missing components directory
} else if (error.message.includes('Component not found')) {
// Handle missing component
} else {
// Handle other errors
}
}
The following components are reserved by HTML:
<area />
<base />
<br />
<col />
<embed />
<hr />
<img />
<input />
<link />
<menuitem />
<meta />
<param />
<path />
<source />
<track />
<wbr />
Naming convention follows celement
. For example: csource
instead of source
to avoid conflicts. The same applies to non-void elements. For example use <chead />
instead of <head />
(<head>
is an HTML element)
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
MIT License - feel free to use this library in your projects!
FAQs
A static HTML component parser and templating tool
The npm package @sojs_coder/htmlc receives a total of 24 weekly downloads. As such, @sojs_coder/htmlc popularity was classified as not popular.
We found that @sojs_coder/htmlc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.