remove-markdown 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
1
+ # This configuration was automatically generated from a CircleCI 1.0 config.
2
+ # It should include any build commands you had along with commands that CircleCI
3
+ # inferred from your project structure. We strongly recommend you read all the
4
+ # comments in this file to understand the structure of CircleCI 2.0, as the idiom
5
+ # for configuration has changed substantially in 2.0 to allow arbitrary jobs rather
6
+ # than the prescribed lifecycle of 1.0. In general, we recommend using this generated
7
+ # configuration as a reference rather than using it in production, though in most
8
+ # cases it should duplicate the execution of your original 1.0 config.
9
+ version: 2
10
+ jobs:
11
+ build:
12
+ working_directory: ~/stiang/remove-markdown
13
+ parallelism: 1
14
+ shell: /bin/bash --login
15
+ # CircleCI 2.0 does not support environment variables that refer to each other the same way as 1.0 did.
16
+ # If any of these refer to each other, rewrite them so that they don't or see https://circleci.com/docs/2.0/env-vars/#interpolating-environment-variables-to-set-other-environment-variables .
17
+ environment:
18
+ CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
19
+ CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
20
+ # In CircleCI 1.0 we used a pre-configured image with a large number of languages and other packages.
21
+ # In CircleCI 2.0 you can now specify your own image, or use one of our pre-configured images.
22
+ # The following configuration line tells CircleCI to use the specified docker image as the runtime environment for you job.
23
+ # We have selected a pre-built image that mirrors the build environment we use on
24
+ # the 1.0 platform, but we recommend you choose an image more tailored to the needs
25
+ # of each job. For more information on choosing an image (or alternatively using a
26
+ # VM instead of a container) see https://circleci.com/docs/2.0/executor-types/
27
+ # To see the list of pre-built images that CircleCI provides for most common languages see
28
+ # https://circleci.com/docs/2.0/circleci-images/
29
+ docker:
30
+ - image: circleci/build-image:ubuntu-14.04-XXL-upstart-1189-5614f37
31
+ command: /sbin/init
32
+ steps:
33
+ # Machine Setup
34
+ # If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
35
+ # The following `checkout` command checks out your code to your working directory. In 1.0 we did this implicitly. In 2.0 you can choose where in the course of a job your code should be checked out.
36
+ - checkout
37
+ # Prepare for artifact and test results collection equivalent to how it was done on 1.0.
38
+ # In many cases you can simplify this from what is generated here.
39
+ # 'See docs on artifact collection here https://circleci.com/docs/2.0/artifacts/'
40
+ - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
41
+ # Dependencies
42
+ # This would typically go in either a build or a build-and-test job when using workflows
43
+ # Restore the dependency cache
44
+ - restore_cache:
45
+ keys:
46
+ # This branch if available
47
+ - v1-dep-{{ .Branch }}-
48
+ # Default branch if not
49
+ - v1-dep-master-
50
+ # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
51
+ - v1-dep-
52
+ # The following line was run implicitly in your 1.0 builds based on what CircleCI inferred about the structure of your project. In 2.0 you need to be explicit about which commands should be run. In some cases you can discard inferred commands if they are not relevant to your project.
53
+ - run: if [ -z "${NODE_ENV:-}" ]; then export NODE_ENV=test; fi
54
+ - run: export PATH="~/stiang/remove-markdown/node_modules/.bin:$PATH"
55
+ - run: npm install
56
+ # Save dependency cache
57
+ - save_cache:
58
+ key: v1-dep-{{ .Branch }}-{{ epoch }}
59
+ paths:
60
+ # This is a broad list of cache paths to include many possible development environments
61
+ # You can probably delete some of these entries
62
+ - vendor/bundle
63
+ - ~/virtualenvs
64
+ - ~/.m2
65
+ - ~/.ivy2
66
+ - ~/.bundle
67
+ - ~/.go_workspace
68
+ - ~/.gradle
69
+ - ~/.cache/bower
70
+ - ./node_modules
71
+ # Test
72
+ # This would typically be a build job when using workflows, possibly combined with build
73
+ # The following line was run implicitly in your 1.0 builds based on what CircleCI inferred about the structure of your project. In 2.0 you need to be explicit about which commands should be run. In some cases you can discard inferred commands if they are not relevant to your project.
74
+ - run: npm test
75
+ # Teardown
76
+ # If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
77
+ # Save test results
78
+ - store_test_results:
79
+ path: /tmp/circleci-test-results
80
+ # Save artifacts
81
+ - store_artifacts:
82
+ path: /tmp/circleci-artifacts
83
+ - store_artifacts:
84
+ path: /tmp/circleci-test-results
package/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  [![CircleCI](https://circleci.com/gh/stiang/remove-markdown.svg?style=svg&circle-token=cac2feef7dc90e6b8578aec361be369412be1c6a)](https://circleci.com/gh/stiang/remove-markdown)
2
2
 
3
3
  ## What is it?
4
- **remove-markdown** is a node.js module that will remove (strip) Markdown formatting from a text. "Markdown formatting" means pretty much anything that doesn’t look like regular text, like square brackets, asterisks etc.
4
+ **remove-markdown** is a node.js module that will remove (strip) Markdown formatting from text.
5
+ *Markdown formatting* means pretty much anything that doesn’t look like regular text, like square brackets, asterisks etc.
5
6
 
6
7
  ## When do I need it?
7
- The typical use case is to display an excerpt of a Markdown text, without the actual Markdown (or rendered HTML, for that matter), for example in a list of posts.
8
+ The typical use case is to display an excerpt from some Markdown text, without any of the actual Markdown syntax - for example in a list of posts.
8
9
 
9
10
  ## Installation
10
11
 
@@ -22,17 +23,19 @@ const plainText = removeMd(markdown); // plainText is now 'This is a heading\n\n
22
23
  You can also supply an options object to the function. Currently, the following options are supported:
23
24
 
24
25
  ```js
25
- var plainText = removeMd(markdown, {
26
+ const plainText = removeMd(markdown, {
26
27
  stripListLeaders: true , // strip list leaders (default: true)
27
28
  listUnicodeChar: '', // char to insert instead of stripped list leaders (default: '')
28
29
  gfm: true // support GitHub-Flavored Markdown (default: true)
30
+ useImgAltText: true // replace images with alt-text, if present (default: true)
29
31
  });
30
32
  ```
31
33
 
32
34
  Setting `stripListLeaders` to false will retain any list characters (`*, -, +, (digit).`).
33
35
 
34
36
  ## TODO
35
- PRs are very much welcome.
37
+ PRs are very much welcome. Here are some ideas for future enhancements:
38
+
36
39
  * Allow the RegEx expressions to be customized per rule
37
40
  * Make the rules more robust, support more edge cases
38
41
  * Add more (comprehensive) tests
package/index.js CHANGED
@@ -3,6 +3,7 @@ module.exports = function(md, options) {
3
3
  options.listUnicodeChar = options.hasOwnProperty('listUnicodeChar') ? options.listUnicodeChar : false;
4
4
  options.stripListLeaders = options.hasOwnProperty('stripListLeaders') ? options.stripListLeaders : true;
5
5
  options.gfm = options.hasOwnProperty('gfm') ? options.gfm : true;
6
+ options.useImgAltText = options.hasOwnProperty('useImgAltText') ? options.useImgAltText : true;
6
7
 
7
8
  var output = md || '';
8
9
 
@@ -20,6 +21,8 @@ module.exports = function(md, options) {
20
21
  output = output
21
22
  // Header
22
23
  .replace(/\n={2,}/g, '\n')
24
+ // Fenced codeblocks
25
+ .replace(/~{3}.*\n/g, '')
23
26
  // Strikethrough
24
27
  .replace(/~~/g, '')
25
28
  // Fenced codeblocks
@@ -34,7 +37,7 @@ module.exports = function(md, options) {
34
37
  .replace(/\[\^.+?\](\: .*?$)?/g, '')
35
38
  .replace(/\s{0,2}\[.*?\]: .*?$/g, '')
36
39
  // Remove images
37
- .replace(/\!\[.*?\][\[\(].*?[\]\)]/g, '')
40
+ .replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, options.useImgAltText ? '$1' : '')
38
41
  // Remove inline links
39
42
  .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
40
43
  // Remove blockquotes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remove-markdown",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Remove Markdown formatting from text",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -40,11 +40,17 @@ describe('remove Markdown', function () {
40
40
  });
41
41
 
42
42
  it('should strip img tags', function () {
43
- const string = '![bear](https://placebear.com/640/480)*Javascript* developers are the _best_.';
43
+ const string = '![](https://placebear.com/640/480)*Javascript* developers are the _best_.';
44
44
  const expected = 'Javascript developers are the best.';
45
45
  expect(removeMd(string)).to.equal(expected);
46
46
  });
47
47
 
48
+ it('should use the alt-text of an image, if it is provided', function () {
49
+ const string = '![This is the alt-text](https://www.example.com/images/logo.png)';
50
+ const expected = 'This is the alt-text';
51
+ expect(removeMd(string)).to.equal(expected);
52
+ });
53
+
48
54
  it('should strip code tags', function () {
49
55
  const string = 'In `Getting Started` we set up `something` foo.';
50
56
  const expected = 'In Getting Started we set up something foo.';