Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible "id" arribute value rather than fixed "toc" #15

Open
KEINOS opened this issue May 6, 2020 · 0 comments
Open

Flexible "id" arribute value rather than fixed "toc" #15

KEINOS opened this issue May 6, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@KEINOS
Copy link
Owner

KEINOS commented May 6, 2020

TL; DR

Add a method that changes the "id" attribute value from "toc" to ad hoc value somewhat like below.

<?php
require_once __DIR__ . '/vendor/autoload.php';

$text_markdown = file_get_contents('SAMPLE.md');

$Parsedown = new \ParsedownToC();

// Add attributes
$Parsedown->setAttributeID('toc');

$html = $Parsedown->text($text_markdown);
echo $html . PHP_EOL;

TS; DR

In the sample at README.md the parsed ToC is parenthesized with DIV tags with id="toc" attributes as below. But I want to change the "id" attribute value to another.

<div id="toc"><ul>
<li><a href="#One">One</a><ul>
<li><a href="#Two">Two</a></li>
</ul>
</li>
<li><a href="#One2">One2</a></li>
</ul></div>
<hr />
<h1 id="One" name="One">One</h1>
<p>Something about One</p>
<h2 id="Two" name="Two">Two</h2>
<p>Something about Two</p>
<h1 id="One2" name="One2">One2</h1>
<p>Something about One2</p>
Sample code

<?php
require_once __DIR__ . '/vendor/autoload.php';

// Sample Markdown with '[toc]' tag included
$text_markdown = file_get_contents('SAMPLE.md');

$Parsedown = new \ParsedownToC();

// Parses '[toc]' tag to ToC if exists
$html = $Parsedown->text($text_markdown);

echo $html . PHP_EOL;
$ cat SAMPLE.md
[toc]

---

# Head1
Sample text of head 1.
## Head1-1
Sample text of head 1-1.
# Head2
Sample text of head 2.
## 見出し2-1
Sample text of head2-1.

This feature will be implemented for more than one 👍

@KEINOS KEINOS added the enhancement New feature or request label May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant