936ef3138ad86e28536ce252d4f10c02e045759e — Michael Rees 6 months ago 9134986
Add option for using nim-html2text
3 files changed, 27 insertions(+), 21 deletions(-)

M roman.nimble
M src/romanpkg/htmlextractor.nim
M README.md => README.md +6 -2
@@ 6,8 6,6 @@ A simple CLI RSS/Atom feed reader.

`roman` is written in [Nim](https://nim-lang.org). Binaries are not yet available, so you will need to build from source. With `nim 0.20` installed, you should simply need to run `nimble build`. 

`roman` uses [`html2text`](http://alir3z4.github.io/html2text/) to display post bodies. You will need to have it installed on your system. [`nim-html2text`](https://git.sr.ht/~reesmichael1/nim-html2text) is being actively developed to replace this dependency.

## Usage

To subscribe to feeds, use the `subscribe` command. For example, 

@@ 30,6 28,12 @@ You can manage your subscriptions by running `roman manage`.

`roman` is still in very early development. [Several improvements are planned!](https://todo.sr.ht/~reesmichael1/roman) However, `roman` is already quite usable.

### Renderers

By default, `roman` uses [`html2text`](http://alir3z4.github.io/html2text/) to display post bodies. You will need to have it installed on your system. 

However, if `roman` is compiled with `-d:internalRenderer`, the experimental [`nim-html2text`](https://git.sr.ht/~reesmichael1/nim-html2text) library will be used instead. This library still needs work, but it removes the need for an external dependency.

## Configuration

You will need to copy the `config/config` file in this repository to `roman/config` within your platform's standard config directory. You can change the values in the file to your taste. 

M roman.nimble => roman.nimble +5 -15
@@ 9,7 9,6 @@ bin           = @["roman"]
binDir        = "bin"

# Dependencies

requires "argparse >= 0.9"

@@ 19,19 18,10 @@ requires "nim >= 0.20.0"
requires "nimpy >= 0.1"
requires "noise >= 0.1"

# Tasks

task run, "Compile and run (release mode)":
    exec "nimble c -r -d:release -o:bin/release/roman src/roman.nim"

task debug, "Compile and run (debug mode)":
    exec "nimble c -r -d:debug -o:bin/debug/roman src/roman.nim"

# Foreign dependencies 
# We can't depend on the -d:internalRenderer flag here, 
# see https://github.com/nim-lang/nimble/issues/605
requires "https://git.sr.ht/~reesmichael1/nim-html2text >= 0.1.0"

when defined(nimdistros):
    import distros
    foreignDep "python-html2text"
  import distros
  foreignDep "python-html2text"

M src/romanpkg/htmlextractor.nim => src/romanpkg/htmlextractor.nim +16 -4
@@ 3,14 3,26 @@ import terminal
import nimpy

import errors
when defined(internalRenderer):
  import html2text

from config import conf

proc extractBody*(body: string): string {.raises: [RomanError].} =
  let width = try:
    min(conf.postWidth, terminalWidth())
    raise newException(RomanError, "could not get terminal width")
    let width = min(conf.postWidth, terminalWidth())
    let html2text = pyImport("html2text").HTML2Text(bodywidth = width)
    result = html2text.handle(body).to(string)
    when defined(internalRenderer):
      # Use nim-html2text if -d:internalRenderer is passed
      return handle(body, maxWidth = width)

      # Otherwise, use the Python version (which needs to be installed)
      let html2text = pyImport("html2text").HTML2Text(bodywidth = width)
      return html2text.handle(body).to(string)
    raise newException(RomanError, "could not use Python module html2text")
    raise newException(RomanError, "error rendering HTML to text: " &