apostrophecms / split-html

Split HTML into two valid fragments wherever a certain selector is matched. Works on the server side.
MIT License
36 stars 13 forks source link

Can not split by <hr> in browser #7

Open wangzhengbo opened 4 years ago

wangzhengbo commented 4 years ago

splitHtml('<p>1<hr>2</p>', 'hr') failed with error: Syntax error, unrecognized expression: 1<p></p>

abea commented 4 years ago

Can you provide a failing test? I used this and it passed.

  it('Splits on an HR', function() {
    var html = '<p>1<hr>2</p>';
    var result = splitHtml(html, 'hr');
    console.info(result); // returns `[ '<p>1</p>', '<hr>', '<p>2</p>' ]`
    assert(result.length === 3);
  });
wangzhengbo commented 4 years ago

Can you provide a failing test? I used this and it passed.

  it('Splits on an HR', function() {
    var html = '<p>1<hr>2</p>';
    var result = splitHtml(html, 'hr');
    console.info(result); // returns `[ '<p>1</p>', '<hr>', '<p>2</p>' ]`
    assert(result.length === 3);
  });

split on an HR failed in browsers(It test it with chrome 86 on Mac). but it's work well when replace br with img.

wangzhengbo commented 4 years ago

Can you provide a failing test? I used this and it passed.

  it('Splits on an HR', function() {
    var html = '<p>1<hr>2</p>';
    var result = splitHtml(html, 'hr');
    console.info(result); // returns `[ '<p>1</p>', '<hr>', '<p>2</p>' ]`
    assert(result.length === 3);
  });

You can test it online at https://codesandbox.io/s/quizzical-mestorf-htzlh

abea commented 4 years ago

I've confirmed this as a bug in the browser. It's not clear why hr tags are being treated differently. We don't have a lot of time for this right now with focus on other projects, so we would welcome contributions for this.

boutell commented 4 years ago

Interesting. It might be possible to use the server build in the browser with cheerio.

On Wed, Oct 28, 2020 at 11:20 AM Alex Bea notifications@github.com wrote:

I've confirmed this as a bug in the browser. It's not clear why hr tags are being treated differently. We don't have a lot of time for this right now with focus on other projects, so we would welcome contributions for this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apostrophecms/split-html/issues/7#issuecomment-718005824, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27PGUVTANQ5GEDKCQ2TSNAZDRANCNFSM4S7GBVPA .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

jcrben commented 3 years ago

I'm pretty sure splitting by <hr> was working previously