Giter VIP home page Giter VIP logo

markdown-to-html's Introduction

node-redis-queue

Overview

This is a very simple queing wrapper for Redis that is intended for communication between separate processes. It comes with two APIs:

  1. Channel -- the push/pop interface

    The process creates an instance of Channel. The sending process uses the Channel instance to push data onto the queue via the push function. The receiving process uses the Channel instance to remove data from the same queue via the pop function, which delivers the data to a callback function which accepts a single data parameter. Some variants of the pop function may have a timeout parameter so they don't block indefinitely.

  2. WorkQueueMgr -- the send/consume interface

    The process creates an instance of WorkQueueMgr. Then, it uses that instance to create one or more instances of WorkQueue, each representing a different queue having a unique name. The sending process uses a WorkQueue instance to send data to the corresponding queue via the send function. The receiving process uses a WorkQueue instance to remove data from the corresponding queue via the consume function, which delivers the data to a callback function which accepts a data parameter and an ack parameter. The latter is a function that is called to indicate that the callback function is complete and is ready to accept some additional data, if any, in the queue. See the usage examples below and also the worker03 and worker04 files in the demo src or lib directories for examples of how to do this. To achieve greater throughput with consume, one may specify the number of async callback functions to operate in parallel. The later feature is referred to as 'arity'. One also may specify a timeout parameter so that consume doesn't block indefinitely.

    consume is different from pop in that a single call to consume can fetch multiple data items from the given queue, while pop must be called repeatedly to fetch items from the queue.

##Details of the Channel Interface

The Channel interface is implemented with a single Channel class, which represents a Redis client connection. It wraps a redis module client object, which may be accessed as a property.

###The public methods of the Channel class are:

####constructor(configFilePath)

Optionally, takes a config file path, which may be overridden by the QUEUE_CONFIG_PATH environment variable. One accesses the constructor most typically by something like var channel = new Channel();.

####connect(onReadyCB)

Obtains a single Redis client connection using the config file information. We refer to this as 'half-duplex' mode. This method calls the given callback when the connection is ready. The client property provides access to this connection, which is used internally for both push/send and pop/consume operations.

####connect2(onReadyCB)

Obtains two Redis client connections using the config file information. We refer to this as 'full-duplex' mode. This method calls the given callback when the connection is ready. The client2 property is used internally for push/send, while the client property is used for pop/consume. Use this feature to avoid hangs on push/send when multiple pop/consume operations may be outstanding.

####attach(client, client2)

This is an alternative to calling connect. It attaches to the given Redis client connection or connections. The client2 parameter is optional and may be omitted.

####push(queueName, data)

Pushes the given data into the queue specified by the given queue name.

####pop(queueName, onDataCB)

Blocks indefinitely waiting for data to become available in the queue specified by the given queue name, at which time it calls the given callback with a single data parameter.

####popTimeout(queueName, timeout, onDataCB)

Blocks waiting for data to become available in the queue specified by the given queue name. While waiting, it may time out after the specified timeout interval (seconds), at which time it emits a timeout event and returns. Once data becomes available, it calls the callback with a single data parameter.

####popAny(queueNames..., onDataCB)

Blocks indefinitely waiting for data to become available in any of the queues specified by the given queue names, at which time it calls the given callback with two parameters: a queue name and a data parameter.

####popAnyTimeout(queueNames..., timeout, onDataCB)

Blocks waiting for data to become available in any of the queues specified by the given queue names. While waiting, it may time out after the specified timeout interval (seconds), at which time it emits a timeout event and returns. Once data becomes available, it calls the callback with two parameters: a queue name and a data parameter.

####clear(queueNames..., onClearCB)

Removes the data from the queues specified by the given queue names. Calls the given callback function once all the given queues have been cleared.

####disconnect()

Quits accepting data and closes the connection.

####end()

Closes the connection.

####shutdownSoon(delay)

Closes the connection after waiting for the redis client's offline_queue_length to go to zero. The delay specifies the interval at which the offline_queue_length will be checked. Defaults to 500 milliseconds.

####commandQueueLength()

Returns the size of the Redis client's command queue (i.e., commands queued to be sent to Redis).

###The public properties of the Channel class are:

####client

This is a Redis client connection used for both push/send and pop/consume operations if opened with connect. However, if opened with connect2, it is used only for pop/consume operations.

####client2

This also is a Redis client connection. If opened with connect, it is the same connection as the client property. However, if opened with connect2, it is a seperate connection used only for push/send operations.

####outstanding

This is a count of the number of pop/consume operations currently outstanding.

##Details of the WorkQueueMgr Interface

This interface is implemented with two classes: WorkQueue and WorkQueueMgr. The WorkQueue class represents a single queue identified by its name. The WorkQueueMgr class represents a collection of WorkQueue instances. It wraps a Channel instance that provides the Redis connection and push and pop functionality for those work queues.

###The public methods of the WorkQueue class are:

####send(data)

Pushes data into the associated work queue.

####consume(onDataCB, arity, timeout)

Consumes data that becomes available in the associated work queue. The arity and timeout parameters are optional and default to 1 and 0 respectively. A zero timeout implies indefinite blocking.

####clear(onClearCB)

Removes the data from the associated queue. Calls the given callback when the operation is complete.

####destroy()

Destroys the meta-data about this WorkQueue instance in the associated WorkQueueMgr class.

###The public properties of the WorkQueue class are:

####queueName

The name of the work queue represented by this class instance.

###The public methods of the WorkQueueMgr class are:

####constructor(configFilePath)

Optionally, takes a config file path, which may be overridden by the QUEUE_CONFIG_PATH environment variable. Creates an internal Channel instance.

####connect(onReadyCB)

Obtains a single Redis client connection using the config file information. We refer to this as 'half-duplex' mode. This method calls the given callback when the connection is ready. The channel's client property provides access to this connection, which is used internally for both push/send and pop/consume operations.

####connect2(onReadyCB)

Obtains two Redis client connections using the config file information. We refer to this as 'full-duplex' mode. This method calls the given callback when the connection is ready. The channel's client2 property is used internally for push/send, while the channel's client property is used for pop/consume. Use this feature to avoid hangs on push/send when multiple pop/consume operations may be outstanding.

####attach(client, client2)

This is an alternative to calling connect. It attaches to a given Redis client connection or connections. The client2 parameter is optional and may be omitted.

####createQueue(queueName)

Returns a WorkQueue instance for the given queue name.

####clear(queueNames..., onClearCB)

Removes the data from one or more queues specified by the given queue names. Calls the given callback function once all the given queues have been cleared.

####clearAll(onClearCB)

Removes data from all the queues that have been created by this WorkQueueMgr instance and not subsequently destroyed. Calls the given callback function once all the queues have been cleared.

####disconnect()

Quits accepting data and closes the connection.

####end()

Closes the connection.

####shutdownSoon(delay)

Closes the connection after waiting for the redis client's offline_queue_length to go to zero. The delay specifies the interval at which the offline_queue_length will be checked. Defaults to 500 milliseconds.

####commandQueueLength()

Returns the size of the Redis client's command queue (i.e., commands queued to be sent to Redis).

###The public properties of the WorkQueueMgr class are:

####channel

This property provides access to the internal Channel instance, which may have been opened in 'half-duplex' mode or 'full-duplex' mode, depending on whether connect or connect2 was used to open the channel.

You may use the channel property, for example, to push response data to an arbitrary result queue when consuming a request queue where the request specifies the name of the response queue to use. The worker04 demo code shows how to do this.

##Events Emitted by Both Interfaces

####'error'

Emitted when an error is reported by Redis.

####'end'

Emitted when a connection to the Redis server has been lost.

####'timeout'

Emitted when a timeout occurs on a popTimeout operation, popAnyTimeout operation, or on a consume operation with a timeout specified. The callback provided to on 'timeout' receives two parameters:

  1. queueNames -- one or more queue names on which the operation was waiting when the timeout occurred.

  2. cancel -- a function that may be called to prevent another outstanding blocking operation from being performed. This is useful, for example, to get a clean exit from a test case.

####'drain'

Emitted when the TCP connection to the Redis server has been buffering, but is now writable. This event can be used to stream commands in to Redis and adapt to backpressure: Call commandQueueLength to detect when the length is too much, then use the 'drain' event to resume sending data to the queue or queues.

##Installation

npm install node-redis-queue --save

##Configuration

Sample configuration files may be found in the sample-configs directory. In each config file, the redis_provider type setting specifies the strategy to use. The verbose setting, if true, specifies to display the config file settings on startup.

The environment variable QUEUE_CONFIG_FILE specifies which config file is to be used. If not set, it defaults to node-redis-queue/redis-queue-config.json, which specifies to use the local Redis server with no password. If you do nothing, that is what you get.

Currently implemented strategies are:

####connStrategyDefaultLocal

Local Redis server, no password

####connStrategyCustom

Configurable host, port, and password; defaults to local Redis server, no password

####connStrategyHerokuRedisCloud

Host, port, and password specified by REDISCLOUD_URL environment variable; if not set, then defaults to local Redis server, no password

####connStrategyBlueMixRedisCloud

Host, port, and password specified by VCAP_SERVICES environment variable; if not set, then defaults to local Redis server, no password

Note that redisQueueConfig determines which strategy is used to configure the client. It is easy to add your own strategy.

##Usage

###Coffescript Usage Examples

See the Coffeescript usage examples here.

###Javascript Usage Examples

See the Javascript usage examples here.

##Running the demos

Instructions for running the demo code may be found here.

##Developer Info

For developers who wish to make changes to the code, information on running the test suite and how to use grunt may be found here;

##Change Log

View the change log here.

##Architecture Notes

The Channel class is a very thin wrapper around existing redis module functions. It delegates all its operations to that module. The Channel class uses different strategies to connect to redis. A config file specifies which strategy to use and also supplies options to the redis module.

The WorkQueueMgr class serves as a factory for WorkQueue class instances.

The WorkQueueMgr class delegates queue send and consume to the Channel class. It maintains a hash of queues created (@queue), which defines which queues currently are valid. For each queue that is consuming data, it maintains an entry in a hash of callbacks (@consumingCB) and and an entry in an ordered list of names of queues currently being consumed (@consumingNames). The ordered list of names represents the priority for consumption of queue data and is used by the consume function as the list of queues to be monitored by qmgr.popAny.

The WorkQueue class is a very simple envelope wrapping four functions, each bound to an instance of the WorkQueueMgr class and the queue name, effectively delegating all operations to the WorkQueueMgr class and to that particular queue.

##Historical Note

Part of this work is derived from node-simple-redis-queue v0.9.3 by James Smith and retains the same license. However, the current version bears almost no resemblance to James' project.

markdown-to-html's People

Contributors

cwjohan avatar mcmarto avatar omrilotan avatar whynot63 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown-to-html's Issues

[DEP0128] DeprecationWarning: Invalid 'main' field

When markdown is run on NodeJS v20 this error is reported:

(node:51931) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/izso/.nvm/versions/node/v20.5.0/lib/node_modules/markdown-to-html/package.json' of 'markdown.js'. Please either fix that or report it to the module author

Installation info:

npm info markdown-to-html

[email protected] | MIT | deps: 7 | versions: 14
Converts markdown text to HTML. A readable stream plus utilities and web demo.
https://github.com/cwjohan/markdown-to-html

keywords: markdown, markdown-to-html, html, render, convert, stream, pipe

bin: markdown, markdownb, github-markdown, github-markdownb

dist
.tarball: https://registry.npmjs.org/markdown-to-html/-/markdown-to-html-0.0.13.tgz
.shasum: 003467759db8b319b06c1d9f092072eb44177f4d
.integrity: sha512-Gj4LOPRgwWKh6i2ccXqpf9mBQEG5gS2qhipCp3bugs32nIvEa0HqeOHW4nkmkGLeozvQRoNmqm3VZ5Aj6c+thg==

dependencies:
gfm-linkify: ^0.1.0        marked: ^0.3.2             open: 0.0.5                pygmentize-bundled: ^2.2.0 request: ^2.47.0           tmp: 0.0.24                yargs: ^1.3.3              

maintainers:
- cwjohan <[email protected]>

dist-tags:
latest: 0.0.13  

published over a year ago by cwjohan <[email protected]>

Header anchor link hrefs are wrong (no user-content- added)

When adding a Table of Contents as follows:

# Table of Contents

* [1. Introduction](#user-content-1-introduction)

and the corresponding heading like so:

# 1. Introduction

An anchor link is generated inside the header tag:

<a id="user-content-1-introduction" class="anchor" href="#1-introduction" aria-hidden="true">
    <span aria-hidden="true" class="octicon octicon-link"></span>
</a>

Notice the href="#1-introduction" meaning that if I was to right-click the anchor link and copy the address it is copied as "www.example.com/document#1-introduction" so when navigating there it doesn't scroll down to the Introduction section as it can't find the anchor link.

I've tried adding my own custom anchor and setting the name and id to "introduction" to no avail.

Is anyone aware of a fix for this?

--help option bug

Great tool! But when I use markdown --help, it returns an error at the last line of the output:

Not enough non-option arguments: got 0, need at least 1

fails in windows 10 with node 7-x

olio@DESKTOP-960H438 C:\Users\Folio\web\tools\vs-code\vscode-tips-and-tricks

markdownb README.md
(node:8060) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
View generated HTML in browser
Temporary files deleted

Folio@DESKTOP-960H438 C:\Users\Folio\web\tools\vs-code\vscode-tips-and-tricks

node -v
v7.10.0

Incorrectly converts line breaks to <br>

Markdown in text format is often hard wrapped at some width (typically 80 characters), to maintain readability with editors that don't no soft wrapping. markdown-to-html incorrectly converts line breaks to <br /> tags.

This is not how github works, as evident in the following gist. Just compare rendered and raw versions, to see that github definitely does not interpret line breaks as <br/>.

https://gist.github.com/raine/dd9a28f763b4a61bc0f56967bb7ff56a
https://gist.githubusercontent.com/raine/dd9a28f763b4a61bc0f56967bb7ff56a/raw/9d8517f1518cfb34d769eced59cce214a3889926/test.md

input

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in the 1960s
with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including
versions of Lorem Ipsum.

output

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem<br>Ipsum has been the industry&#39;s standard dummy text ever since the 1500s, when an<br>unknown printer took a galley of type and scrambled it to make a type specimen<br>book. It has survived not only five centuries, but also the leap into electronic<br>typesetting, remaining essentially unchanged. It was popularised in the 1960s<br>with the release of Letraset sheets containing Lorem Ipsum passages, and more<br>recently with desktop publishing software like Aldus PageMaker including<br>versions of Lorem Ipsum.</p>

Syntax highlighting not working

I did the npm install markdown-to-html -g and then ran github-markdown -h c#-for-scripting.md >c#-for-scripting.html but the resulting .html does not have colour syntax highlighting in it :o(. I am running Ubuntu 16.04.3 LTS. The .md and resulting .html are attaching in a .zip.

markdown and resulting html.zip

Does not process image width properly

There are two ways to specify image size in markdown

![My Image](url =250x) width of image will be 250px (height is auto)

There's also a way to specify css with some flavors:

![My Image](url)(:width: '25rem') neither of these methods work properly.

Inline HTML in markdown is not properly processed.

According to the markdown syntax description inline HTML is supported for those elements not represented in the syntax. When I include the following inline HTML it is not "passed" through to the output as HTML.

Inline HTML that I want written as is to output HTML:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

Instead it's parsed and rendered as follows:

<p>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css&quot;&gt;  </p>
<p>&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js&quot;&gt;&lt;/script&gt;<br>&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;  


</p>

This breaks the desired results when using the HTML file. Please refer to the inline section of the markdown syntax for more information.

https://daringfireball.net/projects/markdown/syntax#html

New version to be released on NPM?

I notice that the README mentions the --template <filename or path> option but this isn't available in the most recent version from NPM (0.0.13).

I could really use this option and wondered if there is any intention to update NPM with the latest version?

Is it possible to just generate the static html file?

I see that a temp file is created, and everything is rendered completely with html and no javascript, is there a flag to just output that file instead of using a tmp and deleting it?

This would be pretty nice, if i were to just look for generating static websites.

not playing well with sierra

i'm running mac os sierra 10.12.1.

ds at selfagency-macpro in ~
» npm install markdown-to-html -g
/usr/local/bin/markdown -> /usr/local/lib/node_modules/markdown-to-html/bin/markdown
/usr/local/bin/github-markdown -> /usr/local/lib/node_modules/markdown-to-html/bin/github-markdown
/usr/local/bin/markdownb -> /usr/local/lib/node_modules/markdown-to-html/bin/markdownb
/usr/local/bin/github-markdownb -> /usr/local/lib/node_modules/markdown-to-html/bin/github-markdownb
/usr/local/lib
└── [email protected]

ds at selfagency-macpro in ~
» markdown
Failed to execute process '/usr/local/bin/markdown'. Reason:
The file '/usr/local/bin/markdown' does not exist or could not be executed.
ds at selfagency-macpro in ~
»

HTML in Markdown

It also converts HTML codes under p, is there any way to include HTML?

<div style="border: 5px solid #ffbe00; text-align: center; padding: 10px">
  Nucleoid has reached 1.0.0 version, but lots of milestones ahead.
  <br />
  Join open source at
  <br />
  <a class="box" href="https://gitlab.com/nucleoid/nucleoid"><img src="/media/gitlab.png" width="50px"/></a>
  <a class="box" href="https://trello.com/b/TZ73H1Fk/nucleoid"><img src="/media/trello.png" width="50px"/></a>
</div>

to

<p>&lt;div style=&quot;border: 5px solid #ffbe00; text-align: center; padding: 10px&quot;&gt;<br>  Nucleoid has reached 1.0.0 version, but lots of milestones ahead.<br>  &lt;br /&gt;<br>  Join open source at<br>  &lt;br /&gt;<br>  &lt;a class=&quot;box&quot; href=&quot;https://gitlab.com/nucleoid/nucleoid&quot;&gt;&lt;img src=&quot;/media/gitlab.png&quot; width=&quot;50px&quot;/&gt;&lt;/a&gt;<br>  &lt;a class=&quot;box&quot; href=&quot;https://trello.com/b/TZ73H1Fk/nucleoid&quot;&gt;&lt;img src=&quot;/media/trello.png&quot; width=&quot;50px&quot;/&gt;&lt;/a&gt;<br>&lt;/div&gt;

</p>

Bad handling of special characters with markdownb

$ echo "Café" > test.md
$ cat test.md 
Café
$ markdown test.md 
<p>Café</p>
$ markdownb test.md 
View generated HTML in browser

The output of markdown is ok, but when using markdownb the generated HTML page contains:

<p>Café</p>

Bad interpreter and bad encoding

The interpreter is set to #!node when it should be to #!/usr/bin/env node

Additionally the npm-installed file for /usr/bin/markdown file is DOS encoded, which causes a "Wrong interpreter node^M" messages like: bash: /usr/bin/markdown: /usr/bin/node^M: bad interpreter: No such file or directory

ID creation?

Creates IDs on headers. This is a no-no. If your document reuses a header, that's bad HTML:

# Product Descriptions (Benefits vs Costs)
## Foo
Some description about Foo.
### Benefits
### Costs
## Bar
Some description about Bar.
### Benefits <-- uses an already created ID
### Costs <-- uses an already created ID

Product Descriptions (Benefits vs Costs)

Foo

Some description about Foo.

Benefits

Costs

Bar

Some description about Bar.

Benefits

Costs

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.