Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
agentmarkdown
Advanced tools
An accurate, extensible, and fast HTML-to-markdown converter.
Agent Markdown is a HTML user agent that parses HTML, performs a document layout according to the CSS stylesheet for HTML and then "renders" the laid out document to Markdown. This results in markdown that looks very similar to the way the HTML document looked when parsed and rendered in a browser (user agent).
import { AgentMarkdown } from "agentmarkdown"
const markdownString = await AgentMarkdown.produce(htmlString)
npm (npm install agentmarkdown
)
You can convert any HTML file to Markdown at the command line using the following command, and the markdown output will be printed to stdout:
agentmarkdown <filename.html>
It also responds to stdin, if you pipe html to it. So you can do things like:
echo "<b>bold</bold>" | agentmarkdown > myfile.md
The above commands assume you installed agentmarkdown with npm install --global agentmarkdown
but it also works with npx
so you can run it without installing like:
npx agentmarkdown <filename.html>
You can view the live online web example at https://agentmarkdown.now.sh.
You can build and the web example locally with the following commands:
cd example/
npm install
npm run start
NOTE: If you have trouble starting the example on macOS related to fsevents
errors, it may require running xcode-select --install
. If that doesn't work, then possibly a sudo rm -rf $(xcode-select -print-path)
followed by xcode-select --install
will be necessary.
To customize how the markdown is generated or add support for new elements, implement the LayoutPlugin
interface to handle a particular HTML element. The LayoutPlugin
interface is defined as follows:
export interface LayoutPlugin {
/**
* Specifies the name of the HTML element that this plugin renders markdown for.
* NOTE: Must be all lowercase
*/
elementName: string
/**
* This is the core of the implementation that will be called for each instance of the HTML element that this plugin is registered for.
*/
layout: LayoutGenerator
}
The LayoutGenerator
is a single function that performs a CSS2 box generation layout algorithm on the an HTML element. Essentially it creates zero or more boxes for the given element that AgentMarkdown will render to text. A box can contain text content and/or other boxes, and each box has a type of inline
or block
. Inline blocks are laid out horizontally. Block boxes are laid out vertically (i.e. they have new line characters before and after their contents). The LayoutGenerator
function definition is as follows:
export interface LayoutGenerator {
(
context: LayoutContext,
manager: LayoutManager,
element: HtmlNode
): CssBox | null
}
An example of how the HTML <b>
element could be implemented as a plugin like the following:
class BoldPlugin {
elementName: "b"
layout: LayoutGenerator = (
context: LayoutContext,
manager: LayoutManager,
element: HtmlNode
): CssBox | null => {
// let the manager use other plugins to layout any child elements:
const kids = manager.layout(context, element.children)
// wrap the child elements in the markdown ** syntax for bold/strong:
kids.unshift(manager.createBox(BoxType.inline, "**"))
kids.push(manager.createBox(BoxType.inline, "**"))
// return a new box containing everything:
return manager.createBox(BoxType.inline, "", kids)
}
}
To initialize AgentMarkdown with plugins pass them in as an array value for the layoutPlugins
option as follows. To customize the rendering an element you can just specify a plugin for the elementName and your plugin will override the built-in plugin.
const result = await AgentMarkdown.render({
html: myHtmlString,
layoutPlugins: [
new BoldPlugin()
]
})
Please give a ⭐️ if this project helped you!
This is a community project. We invite your participation through issues and pull requests! You can peruse the contributing guidelines.
The package is written in TypeScript. To build the package run the following from the root of the repo:
npm run build # It will be built in /dist
We use semantic-release to consistently release semver-compatible versions. This project deploys to multiple npm distribution tags. Each of the below branches correspond to the following npm distribution tags:
branch | npm distribution tag |
---|---|
master | latest |
beta | beta |
To trigger a release use a Conventional Commit following Angular Commit Message Conventions on one of the above branches.
see /docs/todo.md
Copyright © 2019 Scott Willeke.
This project is licensed via Mozilla Public License 2.0.
FAQs
An accurate, extensible, and fast HTML-to-markdown converter.
The npm package agentmarkdown receives a total of 335 weekly downloads. As such, agentmarkdown popularity was classified as not popular.
We found that agentmarkdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.