Skip to content

Commit 5537a44

Browse files
authored
Merge pull request #11 from KEINOS/fix-issue9-exclude-unnecessary-files
Update README.md
2 parents 322d354 + 52a8d0e commit 5537a44

File tree

1 file changed

+149
-8
lines changed

1 file changed

+149
-8
lines changed

README.md

Lines changed: 149 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ Listing Table of Contents Extension for [Parsedown](http://parsedown.org/).
88

99
This [simple PHP file](https://github.com/KEINOS/parsedown-extension_table-of-contents/blob/master/Extension.php) extends [Parsedown (vanilla)](https://github.com/erusev/parsedown) to generate a list of table of contents, aka ToC, from a markdown text given.
1010

11+
```bash
12+
composer require keinos/parsedown-toc
13+
```
14+
15+
```php
16+
<?php
17+
require_once __DIR__ . '/vendor/autoload.php';
18+
19+
$TextMarkdown = file_get_contents('SAMPLE.md');
20+
21+
$Parsedown = new ParsedownToc();
22+
23+
$Body = $Parsedown->text($TextMarkdown);
24+
$ToC = $Parsedown->contentsList();
25+
26+
echo $ToC . PHP_EOL;
27+
echo $Body . PHP_EOL;
28+
```
29+
30+
- Main Class: `ParsedownToc(string $Text)`
31+
- Arguments:
32+
- `$Text`: String of the Markdown text to be parsed.
33+
- Methods:
34+
- `text()`: Returns the Body. (Returns a string of the parsed HTML of the main contents.)
35+
- `contentsList(string $Return_as)`: Returns the ToC. (Returns a string of the table of contents in HTML or JSON.)
36+
- `$Return_as`: `string` or `json` can be specified. (`string`=HTML(default), `json`=JSON)
37+
- Other Methods:
38+
- All the methods of `Parsedown` are available to use.
39+
1140
## Online Demo
1241

1342
https://paiza.io/projects/0TghplxParLqyrP1tjAg6g?locale=en-us
@@ -20,7 +49,7 @@ If you are familiar to [composer](https://en.wikipedia.org/wiki/Composer_(softwa
2049

2150
```bash
2251
# Current stable
23-
composer require keinos/parsedown-toc:1.0.0
52+
composer require keinos/parsedown-toc:1.0.1
2453
# Latest
2554
composer require keinos/parsedown-toc:dev-master
2655
```
@@ -50,10 +79,45 @@ php -r "copy('https://KEINOS.github.io/parsedown-extension_table-of-contents/Ext
5079

5180
## Usage
5281

82+
### Sample scripts(`Main.php`)
83+
84+
<details><summary>Sample Script Without Using Composer</summary><div><br>
85+
86+
```php
87+
<?php
88+
/* Sample script of Parsedown-ToC without using composer */
89+
require_once('Pasedown.php');
90+
require_once('Extension.php');
91+
92+
$textMarkdown =<<<EOL
93+
# Head1
94+
Sample text of head 1.
95+
## Head1-1
96+
Sample text of head 1-1.
97+
# Head2
98+
Sample text of head 2.
99+
## 見出し2-1
100+
Sample text of head2-1.
101+
EOL;
102+
103+
$Parsedown = new ParsedownToc();
104+
105+
$Body = $Parsedown->text($textMarkdown);
106+
$ToC = $Parsedown->contentsList();
107+
108+
echo $ToC . PHP_EOL;
109+
echo '<hr>' . PHP_EOL;
110+
echo $Body . PHP_EOL;
111+
```
112+
113+
</div></details>
114+
115+
<details><summary>Sample Script Using Composer</summary><div><br>
116+
53117
```php
54118
<?php
55-
include_once('Pasedown.php');
56-
include_once('Extension.php');
119+
/* Sample script of Parsedown-ToC using composer */
120+
require_once __DIR__ . '/vendor/autoload.php';
57121

58122
$textMarkdown =<<<EOL
59123
# Head1
@@ -76,6 +140,8 @@ echo '<hr>' . PHP_EOL;
76140
echo $Body . PHP_EOL;
77141
```
78142

143+
</div></details>
144+
79145
### Result
80146

81147
```html
@@ -100,12 +166,87 @@ echo $Body . PHP_EOL;
100166
<p>Sample text of head2-1.</p>
101167
```
102168

103-
## Upcoming feature
169+
### Run(Sample of the steps to take)
170+
171+
This is a log of "how-to" using composer on `bash`.
172+
173+
```shellsession
174+
$ # Create and move to the project directory.
175+
$ mkdir my_sample && cd $_
176+
177+
$ # Create the main script.
178+
$ vi Main.php
179+
...(paste the sample script here)...
180+
181+
$ # Current directory structure
182+
$ tree
183+
.
184+
└── main.php
185+
186+
0 directories, 1 files
187+
188+
$ # Require package that depends the project.
189+
$ # (This will install the "erusev/parsedown", which "keinos/parsedown-toc" depends, too)
190+
$ composer require keinos/parsedown-toc
191+
Using version ^1.0 for keinos/parsedown-toc
192+
./composer.json has been created
193+
Loading composer repositories with package information
194+
Updating dependencies (including require-dev)
195+
Package operations: 2 installs, 0 updates, 0 removals
196+
- Installing erusev/parsedown (1.7.3): Downloading (100%)
197+
- Installing keinos/parsedown-toc (1.0.1): Downloading (100%)
198+
Writing lock file
199+
Generating autoload files
200+
201+
$ # Current directory structure
202+
$ tree
203+
.
204+
├── composer.json
205+
├── composer.lock
206+
├── Main.php
207+
└── vendor
208+
├── autoload.php
209+
├── composer
210+
│   ├── ClassLoader.php
211+
│   ├── LICENSE
212+
│   ├── autoload_classmap.php
213+
│   ├── autoload_files.php
214+
│   ├── autoload_namespaces.php
215+
│   ├── autoload_psr4.php
216+
│   ├── autoload_real.php
217+
│   ├── autoload_static.php
218+
│   └── installed.json
219+
├── erusev
220+
│   └── parsedown
221+
│   ├── LICENSE.txt
222+
│   ├── Parsedown.php
223+
│   ├── README.md
224+
│   └── composer.json
225+
└── keinos
226+
└── parsedown-toc
227+
├── Extension.php
228+
├── LICENSE
229+
├── README.md
230+
└── composer.json
231+
232+
6 directories, 21 files
233+
234+
$ # Run
235+
$ php ./Main.php
236+
... See the Result section above ...
104237

105-
- [ ] `[toc]` markdown tag/element replacing it to the table of contents. ([Issue #2](https://github.com/KEINOS/parsedown-extension_table-of-contents/issues/2))
238+
```
106239

107240
## References
108241

109-
- [Parsedown's Wiki](https://github.com/erusev/parsedown/wiki) @ GitHub
110-
- [Issues of this extension](https://github.com/KEINOS/parsedown-extension_table-of-contents/issues) @ GitHub
111-
- [Issues of Parsedown](https://github.com/erusev/parsedown/issues) @ GitHub
242+
- Repo:
243+
- Source Code: https://github.com/KEINOS/parsedown-extension_table-of-contents @ GitHub
244+
- Archived Package: https://packagist.org/packages/keinos/parsedown-toc @ Packagist
245+
- Support:
246+
- [Parsedown's Wiki](https://github.com/erusev/parsedown/wiki) @ GitHub
247+
- [Issues of this extension](https://github.com/KEINOS/parsedown-extension_table-of-contents/issues) @ GitHub
248+
- [Issues of Parsedown](https://github.com/erusev/parsedown/issues) @ GitHub
249+
250+
## Upcoming feature
251+
252+
- [ ] `[toc]` markdown tag/element replacing it to the table of contents. ([Issue #2](https://github.com/KEINOS/parsedown-extension_table-of-contents/issues/2))

0 commit comments

Comments
 (0)