{"id":13929251,"url":"https://github.com/earldouglas/codedown","last_synced_at":"2025-04-04T22:01:40.355Z","repository":{"id":3499016,"uuid":"49781196","full_name":"earldouglas/codedown","owner":"earldouglas","description":"Extract code blocks from Markdown files","archived":false,"fork":false,"pushed_at":"2024-10-12T14:49:07.000Z","size":318,"stargazers_count":83,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T21:01:34.130Z","etag":null,"topics":["literate-programming"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/earldouglas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-16T16:29:55.000Z","updated_at":"2025-03-18T10:27:58.000Z","dependencies_parsed_at":"2024-10-31T17:12:28.550Z","dependency_job_id":"7a083a22-95d8-43ec-98d3-3133090c3a4a","html_url":"https://github.com/earldouglas/codedown","commit_stats":{"total_commits":65,"total_committers":1,"mean_commits":65.0,"dds":0.0,"last_synced_commit":"909cf724c665a53de2baf173f94441a5302c1163"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earldouglas%2Fcodedown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earldouglas%2Fcodedown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earldouglas%2Fcodedown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earldouglas%2Fcodedown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/earldouglas","download_url":"https://codeload.github.com/earldouglas/codedown/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256093,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["literate-programming"],"created_at":"2024-08-07T18:02:12.824Z","updated_at":"2025-04-04T22:01:40.313Z","avatar_url":"https://github.com/earldouglas.png","language":"JavaScript","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"[![Build Status][build-badge]][build-link]\n[![Coverage Status][coverage-badge]][coverage-link]\n[![npm version][release-badge]][release-link]\n\n[build-badge]: https://github.com/earldouglas/codedown/workflows/build/badge.svg\n[build-link]: https://github.com/earldouglas/codedown/actions\n[coverage-badge]: https://coveralls.io/repos/github/earldouglas/codedown/badge.svg\n[coverage-link]: https://coveralls.io/github/earldouglas/codedown\n[release-badge]: https://badge.fury.io/js/codedown.svg\n[release-link]: https://www.npmjs.com/package/codedown\n\n# Codedown\n\nCodedown is a little utility to extract code blocks from Markdown files.\nInspired by [literate\nHaskell](https://wiki.haskell.org/Literate_programming), Codedown can be\nused to:\n\n* Validate the correctness of code embedded in Markdown\n* Run code embedded in Markdown\n* Ship code and Markdown together in harmony\n\n![](codedown.gif)\n\n## Quicker start\n\nTo skip installing Codedown locally, [try it\nonline](https://earldouglas.github.io/codedown/).\n\n## Quick start\n\nInstall Codedown:\n\n```\n$ npm install -g codedown\n```\n\nRun Codedown:\n\n```\nUsage: codedown \u003clang\u003e [...]\n\nOptions:\n--separator \u003cseparator line\u003e\n--section \u003csection number\u003e\n\nExample:\ncat README.md | codedown haskell --separator=----- --section 1.3\n```\n\nCodedown reads Markdown from stin, extracts the code blocks designated\nas language `\u003clang\u003e`, and outputs them to stdout.  The example above\nextracts the Haskell code from section 1.3 of this file, and outputs it\nwith five dashes in between each block:\n\n```\nx :: Int\nx = 42\n-----\nmain :: IO ()\nmain = putStrLn $ show x\n```\n\nWe can pipe the output of Codedown to a language interpreter:\n\n```\n$ cat README.md | codedown haskell | runhaskell\n42\n```\n\n```\n$ cat README.md | codedown javascript | node\n42\n```\n\n```\n$ cat README.md | codedown scala | xargs -0 scala -e\n42\n```\n\n## Examples\n\nThis readme is a Markdown file, so we can use Codedown to extract code\nfrom it.\n\n### Variables in different languages\n\nIn the following code blocks, let's set `x` to 42 in different\nlanguages:\n\n*Haskell:*\n\n```haskell\nx :: Int\nx = 42\n```\n\n*JavaScript:*\n\n```javascript\nvar x = 42;\n```\n\n*Scala:*\n\n```scala\nval x = 42\n```\n\n### Console output in different languages\n\nNow let's print `x` it to stdout in different languages.  This time, the\ncode blocks are nested within an unordered list:\n\n* *Haskell:*\n\n  ```haskell\n  main :: IO ()\n  main = putStrLn $ show x\n  ```\n\n* *JavaScript:*\n\n  ```javascript\n  console.log(x);\n  ```\n\n* *Scala:*\n\n  ```scala\n  println(x)\n  ```\n\n### Docker\n\nBuild and run a Docker image:\n\n```\ndocker build -t codedown:dev .\n```\n\nUse it to extract `haskell` code blocks and save to `output.hs`:\n\n```\ncat README.md | docker run -i codedown:dev haskell \u003e output.hs\n```\n\n## Sections and subsections\n\nThe section above is 1.3, counting by headings.  It has two subsections\n(1.3.1 and 1.3.2).  We can specify a section number to extract the\ncontent from just that section:\n\n```\n$ cat README.md | codedown haskell --section 1.3\nx :: Int\nx = 42\n\nmain :: IO ()\nmain = putStrLn $ show x\n```\n\n```\n$ cat README.md | codedown haskell --section 1.3.1\nx :: Int\nx = 42\n```\n\n```\n$ cat README.md | codedown haskell --section 1.3.2\nmain :: IO ()\nmain = putStrLn $ show x\n```\n\nWe can also specify a section by heading:\n\n```\ncat README.md | ./codedown.js haskell --section '### Variables in different languages'\nx :: Int\nx = 42\n```\n\n## Wildcard matching\n\nCodedown can use wildcards to match file paths, which are used by some\nmarkdown implementations:\n\n*lib/codedown.js:*\n\n```lib/codedown.js\nvar x = 42;\n```\n\n```\n$ cat README.md | codedown '**/*.js'\nvar x = 42\n```\n\nAdditionally, you can use a special `*` character in place of the language\noption to extract any/all code blocks agnostic of language:\n\n```\n$ cat README.md | codedown '*'\n```\n\n## Separator\n\nIf there are multiple code blocks in the same file, we can specify a\nseparator to insert in between them:\n\n```\n$ cat README.md | codedown haskell --separator=-----\nx :: Int\nx = 42\n-----\nmain :: IO ()\nmain = putStrLn $ show x\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fearldouglas%2Fcodedown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fearldouglas%2Fcodedown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fearldouglas%2Fcodedown/lists"}