{"id":21162694,"url":"https://github.com/ytbryan/emd","last_synced_at":"2025-07-09T15:34:52.299Z","repository":{"id":15068060,"uuid":"77510772","full_name":"ytbryan/emd","owner":"ytbryan","description":"📝 Embeddable markdown with Syntax Highlighting in Rails 5+ products ","archived":false,"fork":false,"pushed_at":"2023-06-03T10:14:58.000Z","size":1409,"stargazers_count":26,"open_issues_count":21,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T13:11:54.294Z","etag":null,"topics":["markdown","rails","template"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/ytbryan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-12-28T06:58:30.000Z","updated_at":"2024-08-05T18:22:47.114Z","dependencies_parsed_at":"2024-08-05T18:35:32.026Z","dependency_job_id":null,"html_url":"https://github.com/ytbryan/emd","commit_stats":{"total_commits":44,"total_committers":5,"mean_commits":8.8,"dds":0.5681818181818181,"last_synced_commit":"bcce9ae6833a1a26c99e1e917ae5548b416991a5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytbryan%2Femd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytbryan%2Femd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytbryan%2Femd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytbryan%2Femd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ytbryan","download_url":"https://codeload.github.com/ytbryan/emd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225565973,"owners_count":17489292,"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":["markdown","rails","template"],"created_at":"2024-11-20T13:32:51.646Z","updated_at":"2024-11-20T13:33:12.431Z","avatar_url":"https://github.com/ytbryan.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Embedded Markdown [![Gem Version](https://badge.fury.io/rb/emd.svg)](https://badge.fury.io/rb/emd)\n\nEmbedded Markdown supports Markdown in Rails views and syntax highlighting at your Markdown code block.\n\n## Installation\n\nAdd these lines to your application's Gemfile:\n\n```ruby\ngem 'coderay' #optional for Syntax Highlighting\ngem 'redcarpet'\ngem 'emd'\n```\n\nAnd then execute:\n\n```\nbundle\n```\n## Usage\n\n### Use it in a Markdown view `markdown.html.md`\n\n1. Create a `markdown.html.md` view at `app/view/home/markdown.html.md` and add the following Markdown code:\n\n```markdown\n## This is a sample Markdown code\n- [google](http://google.com)\n- [emd](https://github.com/ytbryan/emd/)\n```\n\n1. Generate a home controller using the following command `rails generate controller home`\n\n1. Add the following line to `route.rb`: \n```\nget '/markdown', to: 'home#markdown'\n```\n1. And finally, visit the Markdown view at [http://localhost:3000/markdown](http://localhost:3000/markdown)\n\n\n### Use it in a Markdown partial `_component.html.md`\n\n1. Create a `_component.html.md` partial at `app/view/home/_component.html.md`:\n\n```markdown\n### This is a component\n\n- This is item 1\n- This is iiem 2\n- [This is a link to google] (http://google.com)\n```\n\n1. Use this partial using `\u003c%= render \"component\" %\u003e` within any view like at `home/index.html.erb`\n\n1. Add the following line to `route.rb`: \n```\nget '/home', to: 'home#index'\n```\n1. And finally, visit the Rails view with Markdown partial at [http://localhost:3000/home](http://localhost:3000/home)\n\n\n### Syntax Highlighting\n\nTo support syntax highlighting, add `coderay` to Gemfile as shown below: \n\n```ruby\ngem 'coderay'\n```\nRemember to run `bundle install`. \n\nThis will turn all the code block into:\n\n```ruby\n    ```ruby\n        class Something\n        end\n    ```\n```\n\n```ruby\nclass Something\nend\n```\n\nAlso, you can enable inline code highlighting by adding `code` style to your `index.css`\n\n```\ncode {\n  background-color: rgba(27,31,35,.1);\n  border-radius: 3px;\n  font-size: 85%;\n  margin: 0;\n  padding: .2em .4em;\n}\n```\n\n### Enable number lines in your markdown's code block\n\nTo display number lines in your code block, add `emd.js` in `app/assets/javascripts/application.js`\n\n```javascript\n//= require emd\n//= require_tree .\n```\n\nAnd add `emd.css` in `app/assets/stylesheets/application.css`\n\n```css\n*= require emd\n*= require_self\n```\n\n### Changing the color of the code block\n\nTo change the color of the code block, please use the following css selector: \n\n```css\ndiv.code pre {\n  background-color: #fff;\n}\n```\n\nThe default color is `#eee`\n\n\n### Control which extensions Redcarpet uses\n\n`emd` assumes some sane redcarpet extension use (see redcarpets options [here](https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use) and [here](https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch)). If you need to overwrite these in your Rails app, create a file `config/initializers/markdown_template_handler.rb` to overwrite the defaults from [config/initializers/markdown_template_handler.rb](config/initializers/markdown_template_handler.rb) like this:\n\n```\nmodule MarkdownTemplateHandler\n  def self.call(template)\n    compiled_source = erb.call(template)\n    %(Redcarpet::Markdown.new(Redcarpet::Render::HTML,\n                             no_intra_emphasis:            true,\n                             fenced_code_blocks:           true,\n                             # I actually like that, so commented it out:\n                             # disable_indented_code_blocks: true,\n                             space_after_headers:          true,\n                             prettify:                     true,\n                             tables:                       true,\n                             with_toc_data:                true,\n                             autolink:                     true\n                             ).render(begin;#{compiled_source};end).html_safe)\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ytbryan/emd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n\nSpecial thanks to [these folks](http://stackoverflow.com/questions/4163560/how-can-i-automatically-render-partials-using-markdown-in-rails-3/10131299#10131299\n) for making emd possible\n\n\n## TODO\n\n- [x] Syntax highlighting \n- [x] Number lines in code block\n- [ ] Tests\n- [ ] Scaffolders\n- [ ] Example repo\n- [ ] Add a copy button to the code block\n\n\n\n## Benefits\n\nEMD uses a Rails engine and a simple initializer to initiate a markdown template handler with the help of Redcarpet and syntax highlighting from Coderay.\n\nThe motivation is to reuse Markdown file in several of my Rails projects.\n\n- 😊 Reuse Markdown in Rails products\n- 📝 Allow copywriters \u0026 marketers to be involved in building your content easily \n- 📝 Allows you to focus on the content instead of the webpage structure.  \n- 🙌 Supports syntax highlighting via Coderay\n\n\n## Other implementations\n- [Markdown Rails](https://github.com/joliss/markdown-rails)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytbryan%2Femd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fytbryan%2Femd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytbryan%2Femd/lists"}