-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67fcf58
commit e304501
Showing
183 changed files
with
13,589 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: "\U0001F41B Bug" | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**HTML Input** | ||
```html | ||
<h1>Title</h1> | ||
``` | ||
|
||
|
||
**Generated Markdown** | ||
````markdown | ||
# Title | ||
```` | ||
|
||
**Expected Markdown** | ||
````markdown | ||
# Title!!! | ||
```` | ||
|
||
**Additional context** | ||
Add any other context about the problem here. For example, if you changed the default options or used a plugin. Also adding the version from the `go.mod` is helpful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
# Test the latest go version | ||
# and upload the test coverage. | ||
test_latest: | ||
name: Go latest stable | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 'stable' | ||
check-latest: true | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build | ||
run: go build -v . | ||
|
||
- name: Test | ||
run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic | ||
|
||
# - uses: codecov/codecov-action@v4 | ||
# with: | ||
# files: ./coverage.txt | ||
# token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
# Test the latest three golang version | ||
# on different operating systems. | ||
test_versions: | ||
strategy: | ||
matrix: | ||
go: ['1.22'] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
name: Go ${{ matrix.go }} on ${{ matrix.os }} | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Test | ||
run: go test ./... -v -race -cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: goreleaser | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 'stable' | ||
check-latest: true | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v6 | ||
with: | ||
distribution: goreleaser | ||
version: 'latest' | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
# - - - - - General - - - - - # | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
.DS_Store | ||
|
||
|
||
|
||
# - - - - - Project Specific - - - - - # | ||
|
||
NOTES.md | ||
.tmp | ||
|
||
|
||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
# The lines below are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/need to use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
||
version: 2 | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
|
||
# Note: We only use goreleaser for the CLI, | ||
# so we have to go into the "cli" directory. | ||
dir: cli | ||
binary: html2markdown | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of `uname`. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# html-to-markdown | ||
|
||
> [!WARNING] | ||
> This is an **early experimental version** of the library. | ||
> | ||
> We encourage testing and bug reporting. However, please note: | ||
> | ||
> - Not production-ready | ||
> - Default options are well-tested, but custom configurations have limited coverage | ||
> - Functionality is currently restricted | ||
> - Focus is on stabilization and core features | ||
> - No compatibility guarantee | ||
> - Only use `htmltomarkdown.ConvertString()` and `htmltomarkdown.ConvertNode()` from the root package. They are _unlikely_ to change. | ||
> - Other functions and nested packages are _very like_ to change. | ||
--- | ||
|
||
## Golang Library | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
htmltomarkdown "github.com/JohannesKaufmann/html-to-markdown/v2" | ||
) | ||
|
||
func main() { | ||
input := `<strong>Bold Text</strong>` | ||
|
||
markdown, err := htmltomarkdown.ConvertString(input) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println(markdown) | ||
// Output: **Bold Text** | ||
} | ||
``` | ||
|
||
- 🧑💻 [Example code, basics](/examples/basics/main.go) | ||
|
||
The function `htmltomarkdown.ConvertString()` is just a small wrapper around `converter.NewConverter()` and `commonmark.NewCommonmarkPlugin()`. If you want more control, use the following: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/JohannesKaufmann/html-to-markdown/v2/converter" | ||
"github.com/JohannesKaufmann/html-to-markdown/v2/plugin/commonmark" | ||
) | ||
|
||
func main() { | ||
input := `<strong>Bold Text</strong>` | ||
|
||
conv := converter.NewConverter( | ||
converter.WithPlugins( | ||
commonmark.NewCommonmarkPlugin( | ||
commonmark.WithStrongDelimiter("__"), | ||
// ...additional configurations for the plugin | ||
), | ||
), | ||
) | ||
|
||
markdown, err := conv.ConvertString(input) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println(markdown) | ||
// Output: __Bold Text__ | ||
} | ||
``` | ||
|
||
- 🧑💻 [Example code, options](/examples/options/main.go) | ||
|
||
> [!NOTE] | ||
> If you use `NewConverter` directly make sure to also **register the commonmark plugin**. | ||
--- | ||
|
||
--- | ||
|
||
## CLI - Using it on the command line | ||
|
||
Using the Golang library provides the most customization, while the CLI is the simplest way to get started. | ||
|
||
### Installation | ||
|
||
Download the pre-compiled binaries from the [releases page](https://github.com/JohannesKaufmann/html-to-markdown/releases) and copy them to the desired location. | ||
|
||
```bash | ||
html2markdown --version | ||
``` | ||
|
||
> [!NOTE] | ||
> Make sure that `--version` prints `2.X.X` as there is a different CLI for V2 of the converter. | ||
## Usage | ||
|
||
```bash | ||
$ echo "<strong>important</strong>" | html2markdown | ||
|
||
**important** | ||
``` | ||
|
||
```text | ||
$ curl --no-progress-meter http://example.com | html2markdown | ||
# Example Domain | ||
This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission. | ||
[More information...](https://www.iana.org/domains/example) | ||
``` | ||
|
||
_(The cli does not support every option yet. Over time more customization will be added)_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Security Policy | ||
|
||
## Reporting a Vulnerability | ||
|
||
Please report (suspected) security vulnerabilities to johannes@joina.de with the subject _"Security html-to-markdown"_ and you will receive a response within 48 hours. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmd | ||
|
||
func Run( | ||
stdin ReadWriterWithStat, | ||
stdout ReadWriterWithStat, | ||
stderr ReadWriterWithStat, | ||
|
||
osArgs []string, | ||
|
||
release Release, | ||
) { | ||
|
||
cli := CLI{ | ||
Stdin: stdin, | ||
Stdout: stdout, | ||
Stderr: stderr, | ||
|
||
OsArgs: osArgs, | ||
|
||
Release: release, | ||
} | ||
|
||
// - - - - - init - - - - - // | ||
if err := cli.Init(); err != nil { | ||
panic(err) | ||
} | ||
|
||
// - - - - - exec - - - - - // | ||
cli.Execute() | ||
} |
Oops, something went wrong.