
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Codedown is a little utility to extract code blocks from Markdown files. Inspired by literate Haskell, Codedown can be used to:
To skip installing Codedown locally, try it online.
Install Codedown:
$ npm install -g codedown
Run Codedown:
Usage: codedown <lang> [...]
Options:
--separator <separator line>
--section <section number>
Example:
cat README.md | codedown haskell --separator=----- --section 1.3
Codedown reads Markdown from stin, extracts the code blocks designated
as language <lang>
, and outputs them to stdout. The example above
extracts the Haskell code from section 1.3 of this file, and outputs it
with five dashes in between each block:
x :: Int
x = 42
-----
main :: IO ()
main = putStrLn $ show x
We can pipe the output of Codedown to a language interpreter:
$ cat README.md | codedown haskell | runhaskell
42
$ cat README.md | codedown javascript | node
42
$ cat README.md | codedown scala | xargs -0 scala -e
42
This readme is a Markdown file, so we can use Codedown to extract code from it.
In the following code blocks, let's set x
to 42 in different
languages:
Haskell:
x :: Int
x = 42
JavaScript:
var x = 42;
Scala:
val x = 42
Now let's print x
it to stdout in different languages. This time, the
code blocks are nested within an unordered list:
Haskell:
main :: IO ()
main = putStrLn $ show x
JavaScript:
console.log(x);
Scala:
println(x)
The section above is 1.3, counting by headings. It has two subsections (1.3.1 and 1.3.2). We can specify a section number to extract the content from just that section:
$ cat README.md | codedown haskell --section 1.3
x :: Int
x = 42
main :: IO ()
main = putStrLn $ show x
$ cat README.md | codedown haskell --section 1.3.1
x :: Int
x = 42
$ cat README.md | codedown haskell --section 1.3.2
main :: IO ()
main = putStrLn $ show x
We can also specify a section by heading:
cat README.md | ./codedown.js haskell --section '### Variables in different languages'
x :: Int
x = 42
Codedown can use wildcards to match file paths, which are used by some markdown implementations:
lib/codedown.js:
var x = 42;
$ cat README.md | codedown '**/*.js'
var x = 42
Additionally, you can use a special *
character in place of the language
option to extract any/all code blocks agnostic of language:
$ cat README.md | codedown '*'
If there are multiple code blocks in the same file, we can specify a separator to insert in between them:
$ cat README.md | codedown haskell --separator=-----
x :: Int
x = 42
-----
main :: IO ()
main = putStrLn $ show x
FAQs
Extract and run code blocks from Markdown files
The npm package codedown receives a total of 2,888 weekly downloads. As such, codedown popularity was classified as popular.
We found that codedown demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.