Live data from Hacker News

Parsoid in PHP, or There and Back Again

phabricator.wikimedia.org

21–30 of 75 posts

Re: Parsoid in PHP, or There and Back Again

#21
post #12
post #6

Earlier quoted context omitted.

My suspicion is correct - code is full of things like: /\[\[([^\[\]] )\]\]|\{\{([^\{\}] )\}\}|-\{([^\{\}]*)\}-/

I never understood why people find regex so intimidating. Obviously you probably didn't look to find the worst of all, but one you posted is very straightforward.

You jest, but that regex looks machine-generated. My Emacs is full of these in places used for syntax coloring, but I know these are optimized. There's an elisp function, regex-opt, into which you can throw a bunch of strings, and you get out a regex like above.

Re: Parsoid in PHP, or There and Back Again

#22

I would assume that the code is open source? For some reason, I did not manage to find it. Neither linked from this article, nor via the MediaWiki page: https://www.mediawiki.org/wiki/Parsoid Nor via the Phabricator page: https://phabricator.wikimedia.org/project/profile/487/ What am I missing?

> What am I missing?

Google fu.

parsoid source code => https://github.com/wikimedia/parsoid

Re: Parsoid in PHP, or There and Back Again

#23
post #12
post #6

Earlier quoted context omitted.

My suspicion is correct - code is full of things like: /\[\[([^\[\]] )\]\]|\{\{([^\{\}] )\}\}|-\{([^\{\}]*)\}-/

I never understood why people find regex so intimidating. Obviously you probably didn't look to find the worst of all, but one you posted is very straightforward.

Note that HN formatting messed it up (there are stars missing before the first two closing parens). The regex itself is indeed quite straightforward, just a bit hard to read due to all the required backslash-escaping.

Re: Parsoid in PHP, or There and Back Again

#24

I would assume that the code is open source? For some reason, I did not manage to find it. Neither linked from this article, nor via the MediaWiki page: https://www.mediawiki.org/wiki/Parsoid Nor via the Phabricator page: https://phabricator.wikimedia.org/project/profile/487/ What am I missing?

> What am I missing? Google fu. parsoid source code => https://github.com/wikimedia/parsoid

Woops .. so they use Phabricator for issue management and GitHub to host the code?

Re: Parsoid in PHP, or There and Back Again

#25

Earlier quoted context omitted.

> What am I missing? Google fu. parsoid source code => https://github.com/wikimedia/parsoid

Woops .. so they use Phabricator for issue management and GitHub to host the code?

The GitHub repo is a mirror. It has links to more documentation on how the development process works.

Re: Parsoid in PHP, or There and Back Again

#26
Anybody else feeling that strict typing and long var names are not worth all the visual overload?

Example: https://github.com/wikimedia/parsoid/blob/master/src/Parsoid...

This is how I would write the function definition:

    function html2wikitext($config, $html, $options = [], $data = null)
This how Wikimedia did it:

    public function html2wikitext(
        PageConfig $pageConfig, string $html, array $options = [],
        ?SelserData $selserData = null
    ): string
I see this "strictness over readability" on the rise in many places and I think it is a net negative.

Not totally sure, but this seems to be the old JS function definition:

https://github.com/abbradar/parsoid/blob/master/lib/parse.js...

A bit cryptic and it suffers from the typical promise / async / callback / nesting horror so common in the Javascript world:

    _html2wt = Promise.async(function *(obj, env, html, pb)

Re: Parsoid in PHP, or There and Back Again

#27

Earlier quoted context omitted.

Woops .. so they use Phabricator for issue management and GitHub to host the code?

The GitHub repo is a mirror. It has links to more documentation on how the development process works.

I saw that. But why not have the code on Phabricator?

Re: Parsoid in PHP, or There and Back Again

#28

Anybody else feeling that strict typing and long var names are not worth all the visual overload? Example: https://github.com/wikimedia/parsoid/blob/master/src/Parsoid... This is how I would write the function definition: function html2wikitext($config, $html, $options = [], $data = null) This how Wikimedia did it: public function html2wikitext( PageConfig $pageConfig, string $html, array $options = [], ?SelserData $…

I like long names because autocomplete usually means typing speed doesn't matter and they are more verbose, so less thinking when I come back to the code next week. Same goes for strong typing, it makes you think when you write it so you (or somebody else) have to think less when you read it, and obviously it keeps you from making mistakes, helps the IDE make useful suggestions etc.

Re: Parsoid in PHP, or There and Back Again

#29
Last time i tried getting mediawiki up and running as a personal wiki i found out that getting parsoid working was quite a mess. hopefully now it will be easier to get a fully fledged wikimedia installation, together with a visual editor.

Re: Parsoid in PHP, or There and Back Again

#30
post #12

Earlier quoted context omitted.

I never understood why people find regex so intimidating. Obviously you probably didn't look to find the worst of all, but one you posted is very straightforward.

You jest, but that regex looks machine-generated. My Emacs is full of these in places used for syntax coloring, but I know these are optimized . There's an elisp function, regex-opt, into which you can throw a bunch of strings, and you get out a regex like above.

To be honest I was serious. Personally I believe that regular expressions is one of few tools that super useful even for people outside of IT because everyone have to extract of format some text or table data from time to time. You can even learn them just by playing game:

https://regexcrossword.com/

Post reply on HN