zestedesavoir / zmarkdown

Live demo: https://zestedesavoir.github.io/zmarkdown/
MIT License
226 stars 53 forks source link

[API] Heading shift option for single text #448

Closed viki53 closed 2 years ago

viki53 commented 3 years ago

The heading _shift option doesn't seem to work when sending a single string through the API.

A workaround has been to send an array with only that single string, such as:

$query = Http::post(config('zmarkdown.html'), [
    'md' => [
        'text' => $value,
    ],
    'opts' => [
        'heading_shift' => 0,
        'disable_ping' => true,
        'disable_jsfiddle' => false,
        'stats' => false,
    ]
]);
$json = $query->json();

if (isset($json[0]) && isset($json[0]['text'])) {
    $this->attributes['content_html'] = $json[0]['text'];
} else {
    $this->attributes['content_html'] = '';
}

This makes my code rather heavy and a bit dirty-looking, so it would be nice to be able to use this option without needing that extra array structure:

$query = Http::post(config('zmarkdown.html'), [
    'md' => $value,
    'opts' => [
        'heading_shift' => 0,
        'disable_ping' => true,
        'disable_jsfiddle' => false,
        'stats' => false,
    ]
]);
$json = $query->json();

if (isset($json['text'])) {
    $this->attributes['content_html'] = $json[0]['text'];
} else {
    $this->attributes['content_html'] = '';
}
StaloneLab commented 2 years ago

Published in ZMarkdown version 11.1.0. An option enforce_shift was added, see upcoming changelog.

viki53 commented 1 year ago

Works great!

Just missing some documentation for new users, but I looked at the code and found how to use it 🙂