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 8039917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:43:55+00:00 2026-06-05T03:43:55+00:00

I am trying to change the default behavior of Markdown where single line breaks

  • 0

I am trying to change the default behavior of Markdown where single line breaks are not converted to <br />.

I found that github flavored markdown does this, but I am having a hard time converting the rube gsub function to something similar in PHP.

The Ruby code looks like this:

text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
   x.gsub(/^(.+)$/, "\\1  ")
end

But even that I try this simple approach in PHP I see no difference

$text = preg_replace("/^(.+)$/", "\\1", $text);
$text = Markdown($text);

Any help in the conversion from Ruby to PHP will be highly appreciated.

PS. No need for discussion of the behavior in general here, please see the meta question should the markdown renderer treat a single line break as br

  • 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-06-05T03:43:56+00:00Added an answer on June 5, 2026 at 3:43 am

    You are missing two things in your attempt to translate the Ruby code:

    1. The inner regex is inside a Ruby block – gsub! calls it once for every match of its regex parameter, wih the match passed as x. Note the outer regex is a multiline one (as denoted by the final m).
    2. The inner regex inserts two spaces before the matched line breaks – the Markdown processor then converts these to <br /> tags. Your regex just replaces its match by … itself.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to change the default behaviour of a multiselect element, so that
I'm trying to change the default behavior of context menus: Instead of opening on
i'm trying to change the default look and feel for the spotify playlist generated
I was trying to change the compression of some gzip files from the default
What i am trying to do is to change the default homepage for Mozilla
I'm trying to know whether it is possible to change the default android OS
How do I change my applications default language within my application? I am trying
I'm trying to change default firstDayOfWeek for java.util.Calendar from SUNDAY to MONDAY. Is it
I'm trying change an input mask for textbox when the the check box has
I´m trying to change a spring jsp example to use freemarker. I changed all

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.