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

Added code element with code highlighter. #87

Merged
merged 12 commits into from
Oct 29, 2021
Merged

Added code element with code highlighter. #87

merged 12 commits into from
Oct 29, 2021

Conversation

butschster
Copy link
Contributor

@butschster butschster commented Oct 26, 2021

I decided not to use code from nunomaduro/collision package and copied Code Highlighter with some modifications.

  1. I got rid of ConsoleColor class and used css classes for syntax highlighting
  2. Replaced $linesBefore, $linesAfter with $startLine
<code line="20" start-line="14">
    &lt;?php

    /** @test */
    function sentryReport()
    {
        try {
            throw new \Exception('Something went wrong');
        } catch (\Throwable $e) {
            report($e);
        }
    }
</code>

!!! Users have to convert all applicable characters to HTML entities inside code element !!!

Will render

image

fixes #82

@butschster butschster marked this pull request as ready for review October 26, 2021 20:13
@butschster
Copy link
Contributor Author

@xiCO2k Let's start to discuss this PR :)))

@xiCO2k
Copy link
Collaborator

xiCO2k commented Oct 27, 2021

Hey @butschster will check later today. sorry for the delay.

@xiCO2k
Copy link
Collaborator

xiCO2k commented Oct 27, 2021

Just tried and found this issue:

image

check the line 23 on the printscreen.

the code i used:

render(<<<'HTML'
    <code line="20" start-line="14">
        <?php

        /** @test */
        function sentryReport()
        {
            try {
                throw new \Exception('Something went wrong');
            } catch (\Throwable $e) {
                report($e);
            }
        }
    </code>
HTML);

@xiCO2k
Copy link
Collaborator

xiCO2k commented Oct 27, 2021

Ok I changed the encoding and it works well, there is any way to not need to convert the chars?

@butschster
Copy link
Contributor Author

Ok I changed the encoding and it works well, there is any way to not need to convert the chars?

Unfortunately no ((( DOMNode always tries to make HTML valid during export, that's why html inside code element should be converted to html entities.

@xiCO2k
Copy link
Collaborator

xiCO2k commented Oct 27, 2021

Yes you are right. will check the changes, and let you know right after. Thanks.

Copy link
Collaborator

@xiCO2k xiCO2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why not rename the toElement method and call it render like we have on the HtmlRenderer?

Thanks, sorry for the delay reviewing it.

src/Html/CodeRenderer.php Outdated Show resolved Hide resolved
src/HtmlRenderer.php Outdated Show resolved Hide resolved
@butschster
Copy link
Contributor Author

@xiCO2k I like toElement more because this method returns Element object. But if you like render more it's not a problem!

@xiCO2k
Copy link
Collaborator

xiCO2k commented Oct 29, 2021

Lets keep the toElement.

@nunomaduro nunomaduro merged commit c0ec3f0 into nunomaduro:master Oct 29, 2021
@nunomaduro
Copy link
Owner

@butschster Find some issues.

  1. If no "line" is specified it chooses the line 1. Maybe no line at all?
  2. I feel that the left spacing between the code an the code numbers should be removed.

Screenshot 2021-10-29 at 18 47 06

@butschster
Copy link
Contributor Author

@butschster Find some issues.

  1. If no "line" is specified it chooses the line 1. Maybe no line at all?
  2. I feel that the left spacing between the code an the code numbers should be removed.
Screenshot 2021-10-29 at 18 47 06

Yeah, I thought about it. Is there any chance to find out how many spaces we should get rid of?!

Look at this code example:

<code>
 
             public function test() {
                   .....
             }

             public function test1() {
                   .....
             }

      }
?>
</code>

@butschster butschster mentioned this pull request Oct 29, 2021
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

Successfully merging this pull request may close these issues.

[Feature] Code highlighter
3 participants