Code Monkey home page Code Monkey logo

Comments (6)

Azq2 avatar Azq2 commented on June 12, 2024

You means something this?

#!/usr/bin/perl
use warnings;
use strict;
use HTML5::DOM;
use utf8;
use Encode;

my $parser = HTML5::DOM->new;

my $s = HTML5::DOM->new->parse('<b>пыщь пыщь</b>')->at('b')->text;
Encode::_utf8_on($s);

print $s." ололо\n";

Yes, all strings in utf-8. But default behavior - work with bytes.
I will try implement optional utf8 mode.

Something like this:
utf8 => "auto": if passed source with SvUTF8 == 1, then switch to utf8 mode [default]
utf8 => 1: switch to utf8 mode
uft8 => 0: work with bytes

from perl-html5-dom.

zdm avatar zdm commented on June 12, 2024

Yes, exactly.
Usually ->text extracted for comparison or concatenation and it is more handy, if it will be encoded to utf8, because this is text string, not a bytes array.
You can use sv_utf8_decode(sv) - to decode or SvUTF8_on(sv) to just set utf8 flag (will be faster) in your XS code.

from perl-html5-dom.

Azq2 avatar Azq2 commented on June 12, 2024

Implemented in 1.14 version.

Doc:
https://github.com/Azq2/perl-html5-dom#work-with-utf8
https://github.com/Azq2/perl-html5-dom#parser-options
https://github.com/Azq2/perl-html5-dom#utf8

from perl-html5-dom.

zdm avatar zdm commented on June 12, 2024

Seems, that it works.
One more issue:
according to the spec. I can set encoding manually in parser->new:

encoding
Encoding of input HTML, if auto - library can tree to automaticaly determine encoding. (default "auto")

Allowed both encoding name or id.

but if I specify encoding as string

my $parser = HTML5::DOM->new({ encoding => 'WINDOWS-1251' });

it produces error:

 HTML5::DOM::_parseAsync(): invalid encoding value at /usr/perlbrew/perls/perl-5.28.1/lib/site_perl/5.28.1/x86_64-linux-ld/HTML5/DOM.pm line 321.

from perl-html5-dom.

Azq2 avatar Azq2 commented on June 12, 2024

Fixed in 1.15. Regression test added.

from perl-html5-dom.

Azq2 avatar Azq2 commented on June 12, 2024

I think problem resolved. Please, open if not.

from perl-html5-dom.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.