Giter VIP home page Giter VIP logo

commonmark-attributes-extension's Introduction

CommonMark Attributes Extension

Packagist Build Status Scrutinizer Code Quality Code Coverage

The Attributes extension adds a syntax to define attributes on the various HTML elements in markdown’s output.

DEPRECATED

This extension has been deprecated. All of its functionality now exists in league/commonmark 1.5+ under the League\CommonMark\Extension\Attributes namespace, so you should upgrade to that version and use that bundled extension instead of this one.

Installation

This project can be installed via Composer:

composer require webuni/commonmark-attributes-extension

Usage

use League\CommonMark\Converter;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use Webuni\CommonMark\AttributesExtension\AttributesExtension;

$environment = Environment::createCommonMarkEnvironment();
$environment->addExtension(new AttributesExtension());

$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));

echo $converter->convertToHtml('# Hello World!');

Syntax

The basic syntax was inspired by Kramdown‘s Attribute Lists feature.

You can assign any attribute to a block-level element. Just directly prepend or follow the block with a block inline attribute list. That consists of a left curly brace, optionally followed by a colon, the attribute definitions and a right curly brace:

> A nice blockquote
{: title="Blockquote title"}

{#id .class}
## Header

As with a block-level element you can assign any attribute to a span-level elements using a span inline attribute list, that has the same syntax and must immediately follow the span-level element:

This is *red*{style="color: red"}.

commonmark-attributes-extension's People

Contributors

colinodell avatar defr avatar grahamcampbell avatar hason avatar jdavidbakr avatar markhalliwell avatar marktopper avatar onigoetz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

commonmark-attributes-extension's Issues

Update

How to update to the latest commonmark?

does it work with images

Hello!

Tiki CMS is getting a Markdown plugin and uses CommonMark library (https://packagist.org/packages/league/commonmark). Since I need support for some stuff from PHP Markdown Extra I was trying to modify plugin to use erusev/parsedown-extra library and, for some reason it did not work and then tried with michelf/php-markdown which does work so I can use syntax like:

![some image title](url-of-the-image.jpg){.center}

to e.g. pass class (or id) attribute `class="center" to the image.

Now I wonder if this extension allows similar thing since it would be preferrable to use since the official Tiki plugin already uses CommonMark?

Update fail

Hello guys.. I tried update package in my project and i got this error, somebody can help me?
I use: laravel 5.8. and graham-campbell/markdown ^10.3

Capturar

Thanks

Changes in CommonMark breaks Attributes-Extension

(both fresh from github)
Fatal error: Declaration of Webuni\CommonMark\AttributesExtension\AttributesInlineParser::parse() must be compatible with League\CommonMark\Inline\Parser\InlineParserInterface::parse(League\CommonMark\InlineParserContext $inlineContext)

Trivial to fix, but then: Webuni\CommonMark\AttributesExtension\AttributesInlineProcessor::processInlines() must be ... etc

"Unable to find corresponding renderer" when attribute nested inside of emphasis tags

When using an attribute on a link ([link](http://url.com){target="_blank"}) inside of an emphasis tag (_ or *) you receive an error:

Unable to find corresponding renderer for inline type Webuni\CommonMark\AttributesExtension\InlineAttributes

Here is a short script to reproduce the error:

composer.json

{
    "require": {
        "league/commonmark": "^0.15.6",
        "webuni/commonmark-attributes-extension": "^0.5.0"
    }
}

test.php

<?php

require __DIR__ . '/vendor/autoload.php';

use League\CommonMark\Converter;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use Webuni\CommonMark\AttributesExtension\AttributesExtension;

$environment = Environment::createCommonMarkEnvironment();

// Add attributes extension
$environment->addExtension(new AttributesExtension());

$content = [
    "Click here to ... [register now](https://somelink.com){target=\"_blank\"} ... if you haven’t already!",
    "*Click here to ... [register now](https://somelink.com) ... if you haven’t already!*",
    "_Click here to ... [register now](https://somelink.com) ... if you haven’t already!_",
    "*Click here to ... [register now](https://somelink.com){target=\"_blank\"} ... if you haven’t already!*", // throws error
    "_Click here to ... [register now](https://somelink.com){target=\"_blank\"} ... if you haven’t already!_", // throws error
];

// Convert from Markdown to HTML
foreach ($content as $item) {
    try {
        $converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
        $result = $converter->convertToHtml($item);
        echo $result . PHP_EOL;   
    } catch (Exception $e) {
        echo $e->getMessage() . PHP_EOL;
    }
}

php -v

PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

Doesn't work with 0.17

The commonmark lib has been updated to 0.17 and this extension doesn't work with it even with the composer edited. This project also appears to be forgotten or just unmaintained.

Is that the case? Or is their something I'm missing?

Add attributes to code blocks

Hey, I would like to be able to add custom attributes e.g. data-file="controller.phph" to a code block.

I think this is currently not possible, but it would be super awesome if you could implement this behaviour. If however it is possible and I missed it, please let me know how I can do this.

Exception thrown for invalid markdown

When passed the following (invalid) markdown:

{#ANCHOR} [Link](example.com)

missing the line break after the attribute because it's a block level element, an exception is thrown : Call to a member function parent() on null in Webuni\CommonMark\AttributesExtension\AttributesInlineProcessor->processInlines() (line 37)

Given that markdown is hand written, errors can happen, and failing gracefully would be nice :-)

Using this on individual <tr> and <td> tags?

I was hoping to be able to use this with commonmark-table-extension to write things like:

| column name | column name | column name |{.bg-dark-green}
|-|-|-|
| positive value | positive value | positive value |
| negative value | positive value | positive value |

But it doesn't seem to be possible to affect tags like tr, td, th, and the entire thead or tbody. Any ideas?

PHP Deprecated on call to $regex->getPartialRegex

Getting the following warnings:

PHP Deprecated:  RegexHelper no longer uses the singleton pattern. Directly grab the REGEX_ or PARTIAL_ constant you need instead. in vendor/league/commonmark/src/Util/RegexHelper.php on line 168
PHP Deprecated:  RegexHelper no longer supports the getPartialRegex() function. Directly grab the PARTIAL_ constant you need instead. in vendor/league/commonmark/src/Util/RegexHelper.php on line 204
PHP Deprecated:  RegexHelper no longer supports the getPartialRegex() function. Directly grab the PARTIAL_ constant you need instead. in vendor/league/commonmark/src/Util/RegexHelper.php on line 204

It's coming from these two lines in the AttributesUtils class:

$regex->getPartialRegex(RegexHelper::ATTRIBUTENAME),
$regex->getPartialRegex(RegexHelper::ATTRIBUTEVALUESPEC)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.