Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML style output broken #3

Open
Sei-Lisa opened this issue Jan 11, 2014 · 2 comments
Open

XML style output broken #3

Sei-Lisa opened this issue Jan 11, 2014 · 2 comments

Comments

@Sei-Lisa
Copy link
Contributor

Test case:

<?php
include('class.geshi.php');
require_once GESHI_CLASSES_ROOT.'class.geshirenderer.php';
require_once GESHI_RENDERERS_ROOT.'class.geshirendererxml.php';

$geshi = new GeSHi('var a = 1.0;
// comment
function x() {
  var b = Math.PI;
  var c = "string\\n" + \'string\';
  return b;
}
', 'javascript');
$geshi->setRenderer(new GeSHiRendererXML);
echo $geshi->parseCode();

I don't know if that's the right way to set a renderer. Looking at the code, it looks like there are no alternatives.

When run with notices on, it generates a bunch of notices like:

Notice: Array to string conversion in <path>/geshi/classes/renderers/class.geshirendererxml.php on line 98

That's the result of using the styler's getStyle to generate the css attribute contents, as per this snippet (which is the line referenced by the error):

 $result .= ' css="' . $this->_styler->getStyle($context_name) . '"';

because getStyle returns the internal array, not a CSS string which seems to be what that line expects.

This does not clearly demonstrate that the output is wrong (because it crashes later, which is another issue), but is hopefully convincing enough to show that it's broken.

@Sei-Lisa
Copy link
Contributor Author

The basic underlying problem is that the core renderer does not currently output CSS; it deals with style data in the form of an internal array, and that's what getStyle returns.

There are three possible approaches that I can see to fix this:

  1. to copy the CSS generation code from the HTML renderer to the XML one;
  2. to move the CSS generation from the HTML renderer to the base renderer;
  3. to create a new class to deal with style output.

There are arguments against each of these approaches. (1) is the simplest to implement but hardest to maintain, as fixes/improvements should be applied to both stylers and they will usually be desynched. (2) is simple and easy to maintain; the drawback is that the generation code will be present when using renderers that don't need it. (3) is the best but also the hardest to implement, and it implies more code bloat.

I am leaning towards (2).

Sei-Lisa pushed a commit to Sei-Lisa/geshi-1.1 that referenced this issue Jan 15, 2014
The non-sensible ones are XML (which is waiting for Issue GeSHi#3 to be fixed, and will probably resolve itself by then) and Debug (which doesn't deal with colors at all).

TROFF lacks support for background or text colors, so we just add a note.

ANSI lacks alpha support, and has very primitive background color support (8 colors), but it's used. *UNTESTED - MIGHT NOT WORK*

Pango lacks alpha support; background is fully supported otherwise.

HTML completely supports both alpha and background color.
@BenBE
Copy link
Contributor

BenBE commented Jul 24, 2020

Sorry for the very late reply on this. IMHO the XML renderer should basically provide parseable XML output describing all the single tokens encountered while parsing the source. As such retaining the CSS information is not strictly required and could thus be omitted; the encountered warnings should be fixed though.

Cf. geshi-cli.php for an example of how to use the various renderers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants