{"id":15016877,"url":"https://github.com/sinnbeck/markdom","last_synced_at":"2025-04-10T05:08:03.486Z","repository":{"id":49444191,"uuid":"306574025","full_name":"sinnbeck/markdom","owner":"sinnbeck","description":"A markdown parser for laravel for making beautiful html","archived":false,"fork":false,"pushed_at":"2024-03-13T08:10:07.000Z","size":226,"stargazers_count":67,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T05:07:58.887Z","etag":null,"topics":["codehighlight","commonmark","html","laravel","livewire","markdown"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinnbeck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-10-23T08:25:04.000Z","updated_at":"2025-02-23T14:28:36.000Z","dependencies_parsed_at":"2024-09-24T20:41:25.564Z","dependency_job_id":null,"html_url":"https://github.com/sinnbeck/markdom","commit_stats":{"total_commits":32,"total_committers":3,"mean_commits":"10.666666666666666","dds":0.25,"last_synced_commit":"0f01be5092edd2ef866bf3a518bc70d7a8ff2396"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinnbeck%2Fmarkdom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinnbeck%2Fmarkdom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinnbeck%2Fmarkdom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinnbeck%2Fmarkdom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinnbeck","download_url":"https://codeload.github.com/sinnbeck/markdom/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161273,"owners_count":21057555,"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":["codehighlight","commonmark","html","laravel","livewire","markdown"],"created_at":"2024-09-24T19:49:30.733Z","updated_at":"2025-04-10T05:08:03.456Z","avatar_url":"https://github.com/sinnbeck.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/sinnbeck/markdom.svg?style=flat)](https://packagist.org/packages/sinnbeck/markdom)\n[![Downloads on Packagist](https://img.shields.io/packagist/dt/sinnbeck/markdom.svg?style=flat)](https://packagist.org/packages/sinnbeck/markdom)\n![tests](https://github.com/sinnbeck/markdom/workflows/tests/badge.svg)\n\n\n# Introduction\n\nMarkdom is a laravel package to make it simple to convert markdown to beautifully rendered html. It adds classes and allows you to automatically do code highlighting.\n\n![Preview](preview.png)\n\n## Installation\nInstall the package using composer\n```\n$ composer require sinnbeck/markdom\n```\n\nAfter that is a good idea to add the facade to your `config/app.php` aliases array.\n```\n'Markdom' =\u003e Sinnbeck\\Markdom\\Facades\\Markdom::class,\n```\n\n## Publish the config\nTo publish the config file simply run the following to add `markdom.php` to your config directory.\n```\nphp artisan vendor:publish --tag=markdom-config\n```\n\n## Usage\nMarkdom comes with a blade helper to easily convert markdown to html\n```\n@markdom($markdown)\n```\nYou can also call it though the facade\n```\nMarkdom::toHtml($markdown)\n```\n\n## Configuration\nThe main feature of Markdom is to add classes to your rendered html. This requires you to set up a class map in `markdom.php`. This determines which elements are getting what classes.\nHere is a quick example using TailwindCss syntax.\n```\n    'classes' =\u003e [\n        'h1'     =\u003e 'text-3xl font-bold mt-1 mb-2 border-b',\n        'h2'     =\u003e 'text-2xl font-bold my-1 border-b',\n        'h3'     =\u003e 'text-xl font-bold my-1',\n        'p'      =\u003e 'py-2',\n        'ul'     =\u003e 'list-disc list-inside',\n        'ul ul'  =\u003e 'pl-8 list-disc list-inside',\n        'ol'     =\u003e 'list-decimal list-inside',\n        'pre'    =\u003e 'my-1'\n    ],\n```\nThe key can be any css selector, meaning you can also do `ul \u003e li \u003e ul` or even `.classname`. The classes are parsed in the order that they are listed in the config, meaning you can add additional classes to those set before.\n\n```\n    'classes' =\u003e [\n        'h1'     =\u003e 'title text-3xl ',\n        'h2'     =\u003e 'title text-2xl',\n        'h3'     =\u003e 'title text-xl',\n        '.title' =\u003e 'font-bold border-b',\n    ],\n```\nThe above will add the class title to the header elements, and the then `'font-bold border-b'` to each. \\\nResult:\n```\n\u003ch1 class=\"title text-3xl font-bold border-b\"\u003eTitle\u003c/h1\u003e\n\u003ch2 class=\"title text-2xl font-bold border-b\"\u003eSubtitle\u003c/h2\u003e\n\u003ch3 class=\"title text-xl font-bold border-b\"\u003eMore\u003c/h3\u003e\n```\n\n### Adding id and href\nMarkdom makes it simple to add id and links (`\u003ca href /\u003e`) to headings (for use in documentation).\nJust set the `links.enabled` to `true` in the `markdom.php` config file, and Markdom takes care of the rest. \n\nCheck the documentation if the config, for configuration options. \n\n## Markdown configuration\nIt is possible to tweak the parsing of markdown. Under the hood, Mardom uses `league/commonmark`, meaning all settings under the `commonmark` key, is just sent directly to CommonMark.\nSee a list of available settings here: https://commonmark.thephpleague.com/2.3/configuration/#configuration\n\n### Markdown extensions\nCommonMark comes with a lot of extensions. These can be added to the `commonmark_extensions` array which will make them automatically load.\nSee a list of available extensions here: https://commonmark.thephpleague.com/2.3/extensions/overview/\n\n## Code highlighting\nIf you are using markdown for parsing code, you may enable the code highlighter, by setting `MARKDOM_CODE_HIGHLIGHT=true` in your .env file. This will automatically add highlight.js classes to the code found in code tags.\n \n CommonMark will convert \\`somecode\\` and \\\n \\`\\`\\` \\\n somecode \\\n \\`\\`\\` \\\n to `\u003ccode\u003esomecode\u003c/code\u003e` and `\u003cpre\u003e\u003ccode\u003esomecode\u003c/code\u003e\u003c/pre\u003e` which will be passed to `scrivo/highlight.php` (a php implementation of highlight.js).\n \n### Highlight theme and css\n It is possible to have your code styled automatically. This can be done simply by adding the `@markdomStyles()` directive to your page. This will embed the highlight.js css into your page. You can pass the name of a theme to the method, to get a specific stylesheet `@markdomStyles('purebasic')`\n \n### Highlighting theme\n Highlight.js supports 91 themes currently. You can get an array of these themes by using `Markdom::getAvailableThemes()`. This can be useful for rendering a select, if the user is allowed to select theme.\n```\n\u003cselect\u003e\n    @foreach(Markdom::getAvailableThemes() as $style)\n        \u003coption value=\"{{$style}}\"\u003e{{$style}}\u003c/option\u003e\n    @endforeach\n\u003c/select\u003e \n```\n\n### Examples\nController (markdown can be also be loaded from database or a file)\n```\n    public function index()\n    {\n        $markdown = \n\u003c\u003c\u003cmarkdown\n# Title\n## Subtitle\n\n* List item\n* List item 2\n1. Numbered list item\n2. Numbered list item 2\n\n### Code\n\n\\```\n$this-\u003efoo = 'bar';\n\\```\n\nInline code `const $x = [1, 2, 3];`\n\n### Text formatting\n**Bold** \\\n__Bold__ \\\n_Italic_ \\\n~~Crossed~~\n\n### Escaped html\n\u003cscript\u003ealert()\u003c/script\u003e\nmarkdown;\n\n        return view('markdown.index', compact('markdown'));\n    }\n```\nindex.blade.php\n```\n@extends('layouts.app')\n@section('content')\n    @markdom($markdown)\n@endsection\n```\n#### Livewire\nMarkdom also works great with Livewire and does not require any javascript.\n\nYou can get a working example of an autoupdating markdown editor using livewire here: https://github.com/sinnbeck/markdom-livewire\n\n#### Update notice!\nIf you are upgrading from version 1.x to 2.x, be aware that the config format has changed alot due to changes in commonmark! It is therefor a good idea to check the new example config file in the /config directory.\n\n## Testing\nRun tests with\n```\nvendor/bin/pest\n```\n\n## Todo\n\n- [ ] Handle loading of highlight styles using \u003clink syntax\n- [ ] Minification of highlight styles\n- [ ] Guide for using cdn version of highlight styles (inline code breaks!)\n- [ ] Look into passing manually set language to highlight.php\n\n## Credits\n* Markdown parsing: [CommonMark](https://github.com/thephpleague/commonmark)\n* DOM manipulation: [HtmlPageDom](https://github.com/wasinger/htmlpagedom)\n* Code highlighting: [highlight.php](https://github.com/scrivo/highlight.php) \n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinnbeck%2Fmarkdom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinnbeck%2Fmarkdom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinnbeck%2Fmarkdom/lists"}