Skip to content

Commit

Permalink
inital commit of v2
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKaufmann committed Aug 31, 2024
1 parent 67fcf58 commit e304501
Show file tree
Hide file tree
Showing 183 changed files with 13,589 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
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.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
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"
58 changes: 58 additions & 0 deletions .github/workflows/go.yml
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
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
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 }}



27 changes: 27 additions & 0 deletions .gitignore
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/
46 changes: 46 additions & 0 deletions .goreleaser.yaml
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 added CONTRIBUTING.md
Empty file.
120 changes: 120 additions & 0 deletions README.md
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)_
6 changes: 6 additions & 0 deletions SECURITY.md
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.

30 changes: 30 additions & 0 deletions cli/cmd/cli_run.go
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()
}
Loading

0 comments on commit e304501

Please sign in to comment.