Skip to content

Commit

Permalink
fix: move to eslint@9
Browse files Browse the repository at this point in the history
chore: github actions checkout@4
  • Loading branch information
commenthol committed Aug 15, 2024
1 parent 0f4a167 commit d46fc09
Show file tree
Hide file tree
Showing 29 changed files with 626 additions and 487 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

10 changes: 0 additions & 10 deletions .eslintrc.js

This file was deleted.

32 changes: 16 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
# @see: https://github.com/marketplace/actions/setup-node-js-environment

name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: []

env:
CI: "true"

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

node: [ 20, 22 ]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
# cache: 'npm'
- run: npm install --ignore-scripts
- run: npm run ci
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm version
- run: npm install --ignore-scripts
- run: npm run ci

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"semi": false,
"trailingComma": "none"
}
4 changes: 1 addition & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/bin/mdstart.js"
}
]
Expand Down
85 changes: 44 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@

Starts a local server to render "markdown" files within your browser:

* Runs on `localhost:4000`
* Supports [Markdown Syntax][] with [GFM][].
* Markdown rendering based on [markdown-it][].
- Runs on `localhost:4000`
- Supports [Markdown Syntax][] with [GFM][].
- Markdown rendering based on [markdown-it][].
Enabled Plugins for:
* Emojis
* Task lists
* Footnotes
* [KaTeX][]
* [MultiMarkdown table syntax][]
* Includes [markedpp][] as preprocessor.
* Supports syntax highlighting using [highlight.js][]
* For supported markdown syntax see [Cheatsheet][].
* Automatic update in browser after saving edited file. (Tested on Linux, MacOS, Windows)
* Support for [confluencer][]. Needs to be enabled in `/config`.
- Emojis
- Task lists
- Footnotes
- [KaTeX][]
- [MultiMarkdown table syntax][]
- Includes [markedpp][] as preprocessor.
- Supports syntax highlighting using [highlight.js][]
- For supported markdown syntax see [Cheatsheet][].
- Automatic update in browser after saving edited file. (Tested on Linux, MacOS, Windows)
- Support for [confluencer][]. Needs to be enabled in `/config`.

## Table of Contents

<!-- !toc (minlevel=2 omit="Table of Contents") -->

* [Installation](#installation)
* [Usage](#usage)
* [Start the Local Server](#start-the-local-server)
* [Open a markdown file](#open-a-markdown-file)
* [Configuration](#configuration)
* [Help](#help)
* [Cheatsheet](#cheatsheet)
* [Personalisation](#personalisation)
* [Contribution](#contribution)
* [License](#license)
* [References](#references)
- [Installation](#installation)
- [Usage](#usage)
- [Start the Local Server](#start-the-local-server)
- [Open a markdown file](#open-a-markdown-file)
- [Configuration](#configuration)
- [Help](#help)
- [Cheatsheet](#cheatsheet)
- [Personalisation](#personalisation)
- [Contribution](#contribution)
- [License](#license)
- [References](#references)

<!-- toc! -->

Expand All @@ -59,7 +59,7 @@ mdstart
Open the given link <http://localhost:4000/?session=...> in your browser and
navigate to the markdown file.

__Note__: The local server can only be reached from your local computer on port 4000.
**Note**: The local server can only be reached from your local computer on port 4000.
Any remote access from other computers to your files is denied.
An internal session is used, so you'll need to either start with a file or use the provided
link with the session parameter.
Expand Down Expand Up @@ -87,7 +87,9 @@ mdstart /config
```
mdstart --help
```

or

```
man mdstart
```
Expand All @@ -104,17 +106,18 @@ mdstart /cheatsheet

In `config.js` you can change several settings to fit your needs. These include:

* **Browser**: Default browser of MacOS, Linux or Windows is used.
* **Markdown** options: Change the options how [markdown-it][] processes your markdown files.
* **Markdown PP** options: Change the options how [markedpp][] pre-processes your markdown files.
- **Browser**: Default browser of MacOS, Linux or Windows is used.
- **Markdown** options: Change the options how [markdown-it][] processes your markdown files.
- **Markdown PP** options: Change the options how [markedpp][] pre-processes your markdown files.

Install personalized version:

1. Clone this repo
````

```
git clone --depth 2 https://github.com/commenthol/md-fileserver.git
cd md-fileserver
````
```

2. Make your changes in `./config.js`
3. Install with `npm i -g` from same folder.
Expand All @@ -128,7 +131,7 @@ all code is your original work.

## License

Copyright (c) 2014-present commenthol
Copyright (c) 2014-present commenthol
Software is released under [MIT License][].

Bundled fonts from [KaTeX][] by Khan Academy - https://github.com/Khan/KaTeX -
Expand All @@ -138,16 +141,16 @@ Bundled fonts from [KaTeX][] by Khan Academy - https://github.com/Khan/KaTeX -

<!-- !ref -->

* [Cheatsheet][Cheatsheet]
* [confluencer][confluencer]
* [GFM][GFM]
* [highlight.js][highlight.js]
* [KaTeX][KaTeX]
* [Markdown Syntax][Markdown Syntax]
* [markdown-it][markdown-it]
* [markedpp][markedpp]
* [MIT License][MIT License]
* [MultiMarkdown table syntax][MultiMarkdown table syntax]
- [Cheatsheet][Cheatsheet]
- [confluencer][confluencer]
- [GFM][GFM]
- [highlight.js][highlight.js]
- [KaTeX][KaTeX]
- [Markdown Syntax][Markdown Syntax]
- [markdown-it][markdown-it]
- [markedpp][markedpp]
- [MIT License][MIT License]
- [MultiMarkdown table syntax][MultiMarkdown table syntax]

<!-- ref! -->

Expand Down
35 changes: 18 additions & 17 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# TODO

* features
* [x] automatically start server with mdopen
* [x] only show markdown files in Index
* [x] auto update on file changes (using websockets)
* [x] autoupdate port in `reload.js`
* [x] change markdown parser from `marked` to `markdown-it`
* [x] nicer css template(s) for highlight
* [x] enable config changes via server
* [ ] write pid file of server
* [ ] allow stoping the server with `mdstart --stop`
- features

* fixes
* [x] allow websocket connections from multiple browsers
* [x] disconnect websocket connections if closed
* [x] autoreconnect browser websocket connection
* [x] watchFile not working on OSX
* [x] fix problems with URI encoding
* [x] secure server with session
- [x] automatically start server with mdopen
- [x] only show markdown files in Index
- [x] auto update on file changes (using websockets)
- [x] autoupdate port in `reload.js`
- [x] change markdown parser from `marked` to `markdown-it`
- [x] nicer css template(s) for highlight
- [x] enable config changes via server
- [ ] write pid file of server
- [ ] allow stoping the server with `mdstart --stop`

- fixes
- [x] allow websocket connections from multiple browsers
- [x] disconnect websocket connections if closed
- [x] autoreconnect browser websocket connection
- [x] watchFile not working on OSX
- [x] fix problems with URI encoding
- [x] secure server with session
76 changes: 45 additions & 31 deletions bin/mdstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ const { render } = require('../lib/markd')

const argv = () => {
const argv = process.argv.slice(2)
const cmd = Object.assign({
browser: config.browser[process.platform],
port: config.port
}, appConfig.config, {
confluencer: undefined,
confluenceHtml: undefined
})
const cmd = Object.assign(
{
browser: config.browser[process.platform],
port: config.port
},
appConfig.config,
{
confluencer: undefined,
confluenceHtml: undefined
}
)
while (argv.length) {
const arg = argv.shift()
if (['-p', '--port'].includes(arg)) {
Expand Down Expand Up @@ -47,53 +51,63 @@ isPortOpen(cmd, (isOpen) => {

const token = appConfig.token()
const filename = path.resolve(process.cwd(), cmd.file || '')
const url = `http://${config.hostname}:${cmd.port}` +
filename2uri(filename) + `?session=${token}`
const url =
`http://${config.hostname}:${cmd.port}` +
filename2uri(filename) +
`?session=${token}`

if (cmd.output) {
const _config = Object.assign({}, config, appConfig.config)
render(filename, '', _config)
.then(data => fs.writeFileSync(cmd.output, data))
.then((data) => fs.writeFileSync(cmd.output, data))
.catch(console.error)

return
}

if (!isOpen) {
const { port, confluencer, confluenceHtml } = cmd
require('../lib').start({ port, confluencer, confluenceHtml, quiet: startBrowser })
require('../lib').start({
port,
confluencer,
confluenceHtml,
quiet: startBrowser
})
// child.execFile('node', [path.resolve(__dirname, 'start.js')],
// isWin32 ? { windowsHide: true, shell: true } : void 0)
}

if (startBrowser) {
setTimeout(function () {
const [exe, ...args] = cmd.browser
args.push(url)
const www = child.spawn(exe, args)
www.on('error', (err) => {
if (err.code === 'ENOENT') {
console.log('\n' +
` Error: Starting browser with "${exe}" failed.\n` +
` Open: ${url}\n`
)
}
})
}, isOpen ? 0 : 250)
setTimeout(
function () {
const [exe, ...args] = cmd.browser
args.push(url)
const www = child.spawn(exe, args)
www.on('error', (err) => {
if (err.code === 'ENOENT') {
console.log(
'\n' +
` Error: Starting browser with "${exe}" failed.\n` +
` Open: ${url}\n`
)
}
})
},
isOpen ? 0 : 250
)
} else {
console.log('\n' +
` Open: ${url}\n`)
console.log('\n' + ` Open: ${url}\n`)
}
})

/* eslint-disable no-console */

function version () {
function version() {
console.log('v' + require('../package.json').version)
process.exit(0)
}

function help () {
console.log(fs.readFileSync(path.resolve(__dirname, '..', 'man', 'mdstart.txt'), 'utf8'))
function help() {
console.log(
fs.readFileSync(path.resolve(__dirname, '..', 'man', 'mdstart.txt'), 'utf8')
)
process.exit(0)
}
Loading

0 comments on commit d46fc09

Please sign in to comment.