Giter Club home page Giter Club logo

readable's Introduction

readable's People

Contributors

bobheadxi avatar mjurbanski-reef avatar rooterkyberian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

readable's Issues

ERROR failed to render 'TEST.md', aborting: ReferenceError: document is not defined

./dev readable fmt TEST.md --log-level DEBUG results in:
ERROR failed to render 'TEST.md', aborting: ReferenceError: document is not defined

after adding log.error(err.stack); to lib/walk.ts I'm getting:

ERROR fmt: ReferenceError: document is not defined
    at Object.decodeEntity [as default] (https://jspm.dev/npm:[email protected]/decode-entity!cjs:12:14)
    at value (https://jspm.dev/npm:[email protected]/dist/parse!cjs:1448:76)
    at go (https://jspm.dev/npm:[email protected]/dist/parse!cjs:810:13)
    at main (https://jspm.dev/npm:[email protected]/dist/parse!cjs:800:11)
    at Object.write (https://jspm.dev/npm:[email protected]/dist/parse!cjs:744:5)
    at subcontent (https://jspm.dev/npm:[email protected]/_/4550b33d.js:133:17)
    at subtokenize (https://jspm.dev/npm:[email protected]/_/4550b33d.js:54:23)
    at postprocess (https://jspm.dev/npm:[email protected]/dist/postprocess!cjs:10:11)
    at fromMarkdown (https://jspm.dev/npm:[email protected]!cjs:32:28)
    at parse (https://jspm.dev/npm:[email protected]!cjs:12:12)
ERROR failed to render 'TEST.md', aborting: ReferenceError: document is not defined

As a workaround, I applied this patch:

diff --git a/readable.ts b/readable.ts
index b44ed82..1cf867a 100644
--- a/readable.ts
+++ b/readable.ts
@@ -7,6 +7,12 @@ import check from "./cmd/check.ts";
 import fmt, { FmtOptions } from "./cmd/fmt.ts";
 import setupLogger from "./lib/setupLogger.ts";
 
+import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";;
+
+const parser = new DOMParser();
+const doc = parser.parseFromString("<!DOCTYPE html><html><head></head><body></body></html>", "text/html");
+globalThis.document = doc;
+
 const cli = cac("readable")
   .version(READABLE_VERSION)
   .help()

which allowed me to execute readalbe successfully.
I don't know if this is an acceptable long term fix or not.
It seems like for some reason a browser versions of dependencies are pulled in and it would be probably better to fix that problem.

Formats in the middle of sentence when faces `e.g.`

TSIA.

To reproduce (file named hir.md):

For example, the contents of individual items (e.g. modules, functions, traits, impls, etc) in the HIR are not immediately accessible in the parents.

run

readable fmt hir.md

Result:

For example, the contents of individual items (e.g.
modules, functions, traits, impls, etc) in the HIR are not immediately accessible in the parents.

Expected result:
File not to change.

Issue occurs in master commit 8e53ead and v2.2 release.

Deno install fails with missing version.ts

$ deno install --unstable --allow-read --allow-write https://deno.land/x/readable/readable.ts
Download https://deno.land/x/readable/readable.ts
Warning Implicitly using latest version (v0.2.0) for https://deno.land/x/readable/readable.ts
Download https://deno.land/x/[email protected]/readable.ts
Download https://deno.land/x/[email protected]/deps/cac.ts
Download https://deno.land/x/[email protected]/cmd/fmt.ts
Download https://deno.land/x/[email protected]/version.ts
Download https://deno.land/x/[email protected]/cmd/check.ts
Download https://deno.land/x/[email protected]/markdown/format.ts
Download https://deno.land/x/[email protected]/lib/walk.ts
Download https://deno.land/x/[email protected]/lib/diff.ts
Download https://deno.land/x/[email protected]/deps/fs.ts
Download https://deno.land/x/[email protected]/deps/remark.ts
Download https://deno.land/x/[email protected]/plugins/mod.ts
Download https://deno.land/x/[email protected]/deps/colors.ts
Download https://deno.land/x/[email protected]/deps/diff.ts
Download https://deno.land/x/[email protected]/plugins/readable/mod.ts
Download https://deno.land/x/[email protected]/plugins/thirdparty/mod.ts
Download https://deno.land/x/[email protected]/plugins/readable/reflow.ts
Download https://deno.land/x/[email protected]/plugins/thirdparty/stringify.ts
Download https://deno.land/x/[email protected]/plugins/thirdparty/frontmatter.ts
Download https://deno.land/x/[email protected]/markdown/ast.ts
error: Import 'https://deno.land/x/[email protected]/version.ts' failed: 404 Not Found
    at https://deno.land/x/[email protected]/readable.ts:1:0

$ deno --version
deno 1.11.1 (release, x86_64-unknown-linux-gnu)
v8 9.1.269.35
typescript 4.3.2

Add a LICENSE file

Hi, just a note that there's no LICENSE file in this repository that I can find - it would be great if this was released under an open source licence!

Readable throws an error when it encounters multi line link element

File to reproduce (minimal.md):

We want to convert this into an error. In some cases, there may be an
existing error for this scenario. In others, we will need to allocate a
fresh diagnostic code.  [Instructions for allocating a fresh diagnostic
code can be found here.](./diagnostics/diagnostic-codes.md) You may want
to mention in the extended description that the compiler behavior
changed on this point, and include a reference to the tracking issue for
the change.

Running

readable check minimal.md

On master and v2.2 it throws error:

ERROR failed to render '/home/muradb/personal/rustc-dev-guide/minimal.md', aborting: Error: Cannot take length of multi-line node '[object Object]'
Toggle full backtrace of error
Error: Cannot take length of multi-line node '[object Object]'
    at nodeLength (file:///home/muradb/personal/readable/markdown/ast.ts:92:16)
    at ReflowParagraphState.addRawNode (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:84:31)
    at processParent (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:288:41)
    at reflowParagraph (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:321:3)
    at visit (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:335:9)
    at file:///home/muradb/personal/readable/plugins/readable/reflow.ts:338:42
    at Array.forEach (<anonymous>)
    at visit (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:338:23)
    at transformer (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:344:5)
    at wrapped (https://jspm.dev/npm:[email protected]!cjs:21:19)

Upon further having some console.log s in nodeLength function, it's clear that the error occurs because of link element in the example, specifically when it tries to check for if node is literal:

if (isLiteralNode(n)) return n.value.length;

which link element is not, so it just throws error. I am not sure about the whole codebase, but if you tell me what's it supposed to do when it encounters a link element, I can send a pull request.

reflow: look-ahead for breaking decisions

theres still a fault in the heuristic where we don't break on every sentence, just those that aren't wicked short. however, if we get a short sentence followed by a long boi you get two super long sentences:

deno run readable-demo.ts fixture2
# Document

hello world! this is a document. here is a sentence.
and here is another `sentence`! with a [a link](https://bobheadxi.dev) and **emphasis [bold link](https://github.com/bobheadxi)** and *italics* and ~~strike~~ and a ![cute image](https://bobheadxi.dev/assets/images/profile.jpg).

should be:

# Document

hello world! this is a document. here is a sentence.
and here is another `sentence`!
with a [a link](https://bobheadxi.dev) and **emphasis [bold link](https://github.com/bobheadxi)** and *italics* and ~~strike~~ and a ![cute image](https://bobheadxi.dev/assets/images/profile.jpg).

Document code structure and implementation

This is similar to #4, but instead of describing just the goals and motivation of the project (the "what" and "why"), this issue focuses on the "how".

Specifically, it would be nice to have an overview of that the code does and how it works. This documentation could live in README.md or in CONTRIBUTING.md (or both). I would expect at least a link to https://github.com/bobheadxi/readable/blob/main/plugins/readable/reflow.ts, which, if I understand correctly, is core of the project.

reflow: already line-broken lists

input:

1. use the Golang [abstract syntax tree parser](https://golang.org/pkg/go/ast/)
  to identify "selectors", such as `my.value` (this approach did not have the
  `SELECT` syntax described early - an example of the initial proposal's syntax
  was simply `container.count - 1`. In this case, `container.count` is a valid Go selector
  that would be recognised by the AST parser)
2. evalaute the selectors using the `gojsonq` library
3. 3. perform expression arithmetic using the `govaluate` library with the selected
  values as [parameters to the expression](https://github.com/Knetic/govaluate#how-do-i-use-it)

got:

1. use the Golang [abstract syntax tree parser](https://golang.org/pkg/go/ast/)

to identify "selectors", such as `my.value` (this approach did not have the `SELECT` syntax described early - an example of the initial proposal's syntax was simply `container.count - 1`.
In this case, `container.count` is a valid Go selector that would be recognised by the AST parser) 2.
evalaute the selectors using the `gojsonq` library 3.
perform expression arithmetic using the `govaluate` library with the selected values as [parameters to the expression](https://github.com/Knetic/govaluate#how-do-i-use-it)

definitely wrong :( related: #7

suggestion: expose a pre-commit hook for readable

Readable is looking very cool for my use case of linting Markdown file styling. My ideal interaction pattern would be to add Readable's docker container as a pre-commit hook so it ran on every user's commit. Would you be interested in supporting that? It's a pretty minimal addition to this repo, e.g. two ids, readable-fmt and readable-check.

Instructions on how to set up:

https://pre-commit.com/#docker_image

Example of actionlint's docker image being set up as a pre-commit hook: https://github.com/rhysd/actionlint/blob/main/.pre-commit-hooks.yaml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.