Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3403906
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:19:03+00:00 2026-05-18T05:19:03+00:00

Im trying to get GeSHi to work with markdown. A simple use for Geshi

  • 0

Im trying to get GeSHi to work with markdown.

A simple use for Geshi is as follows:

$geshi = new GeSHi($message, 'c');
print $geshi->parse_code();

The above code takes in the whole of message and turns it into Highlighted code

I also have my Markdown Function

print Markdown($message);

I was trying to use call back function to preg_match the <pre> tags returned from markdown and run the geshi->parse_code(); function on the returned values

Here is my code

print preg_replace_callback(
   '/<pre.*?>(.*?[<pre.*?>.*<\/pre>]*)<\/pre>/gism',
    create_function(
        // single quotes are essential here,
        // or alternative escape all $ as \$
        '$matches',
        '$geshi = new GeSHi($matches[0], \'php\'); return $geshi->parse_code()'
    ),
    Markdown($blog_res['message']));

Am i on the right track?

Is My Regex right? it works on http://gskinner.com/RegExr/

Thanks for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:19:04+00:00Added an answer on May 18, 2026 at 5:19 am

    it was the regex 🙁

    instead of

    /<pre.*?>(.*?[<pre.*?>.*<\/pre>]*)<\/pre>/gism 
    

    use (remove the global flag)

    /<pre.*?>(.*?[<pre.*?>.*<\/pre>]*)<\/pre>/ism 
    

    But if you are using markdown, you have to remember to compensate for the code blocks that are on thier own therefore you need to replace only the ones that are in the format of <pre><code>...MyCode</code></pre> and leave out Hello <code>MyCode</code> Therefore you need the following

    '/<pre.*?><code.*?>(.*?[<pre.*?><code.*?>.*<\/code><\/pre>]*)<\/code><\/pre>/ism',
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get a simple COUNT from a table that takes a couple of
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
Trying to get a JSON output to work with jqGrid 'userdata' option. The example
When I'm trying get method from remote webservice it gives me error. My code
Ok, I just bought the new 27 inch iMac and I am trying get
Trying to get custom Done button in Utility Application Create new project in Xcode
I'm trying get LocalConnection to work between two swf's placed within two different IFRAMES.
I am trying get Javascript popup calendar control to work which doesnt work. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.