thephpleague / html-to-markdown

Convert HTML to Markdown with PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extraneous spaces added to beginnings of lines

strider72 opened this issue · comments

When converting to markdown, if HTML is not contained in HTML elements, the script adds a single space to the start of every line beyond the first line.

Actual example (with text modified for anonymity.) (Yes, I know this is super primitive clunky HTML):

<b>Review Responsibilities:</b><br><br>

- Have iPad <i>and</i> charger in your possession<br><br>
- Periodically refresh page<br><br>
- Keep in touch<br><br>

<b>Designate and ensure alternate personnel are in place</b><br><br>

results in this:

**Review Responsibilities:**  
  
 - Have iPad *and* charger in your possession

 - Periodically refresh page

 - Keep in touch
  
 **Designate and ensure alternate personnel are in place**

Note the extraneous leading spaces on all text lines other than the first.

Technically I could just run a separate script to chop leading spaces off each line, except sometimes they're supposed to be there (e.g. indented lists), so no... I can't reliably do that without affecting the real contents

Could you share some more info? I can't reproduce this. This is my testcode:

require 'vendor/autoload.php';

use League\HTMLToMarkdown\HtmlConverter;

$converter = new HtmlConverter();

$html = "<b>Review Responsibilities:</b><br><br>

- Have iPad <i>and</i> charger in your possession<br><br>
- Periodically refresh page<br><br>
- Keep in touch<br><br>

<b>Designate and ensure alternate personnel are in place</b><br><br>";

$markdown = $converter->convert($html);

echo $markdown;

Then it outputs the following:

➜  html-to-markdown git:(master) ✗ php test.php
**Review Responsibilities:**  
  
- Have iPad *and* charger in your possession  
  
- Periodically refresh page  
  
- Keep in touch  
  
**Designate and ensure alternate personnel are in place**  
  %                                                                                                                                                                                                                                     ➜  html-to-markdown git:(master) ✗ 

I think it's working like expected.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.