0

When I include code samples within a phrase of one of my answers, I find it hard to see that code from the rest of the phrase.
Because of this, I like to put quotes around code, like this: 'code sample', or this: "code sample".

Since we already have a shortcut for making text a code sample (CTRL+K), I would like to reuse that shortcut in order to put quotes around it.

That would mean the following phrase:

my clever answer with a code sample function() call in it

would become, with 'code sample function()' highlighted:

  • first CTRL+K:

my clever answer with a code sample function() call in it

(just like today)

  • second CTRL+K:

my clever answer with a "code sample function()" call in it

(oh! I see now you function() call)

  • third CTRL+K:

my clever answer with a 'code sample function()' call in it

(a more subtle way to signal the code sample part of the phrase)

  • fourth CTRL+K:

my clever answer with a code sample function() call in it

(back to normal, no more <code> around the text, just like today, and you can then repeat the cycle)

I have tested this feature in my own version of WMD and it works great (see my answer below).
But before bugging Dana.E.Robinson with a patch, I would like to see what the community thinks about this proposition.

4
  • I'm not sure why you have said in several comments that color or border is not possible. It would be a simple CSS rule. I've created a Greasemonkey script that does this, actually: meta.stackexchange.com/questions/15429/…
    – Kip
    Aug 19, 2009 at 13:18
  • 1
    Blast from the past :) Im tagging this status-status completed, since we eventually went with Jon's suggestion a long time ago. It doesn't fulfill your request as stated, but it solves your issue.
    – balpha StaffMod
    Sep 13, 2012 at 7:24
  • @balpha has it been 3 years already...
    – VonC
    Sep 13, 2012 at 9:42
  • Tell me about it. The "we" in my comment is actually a lie. Back in those days, I was just a smartass running around on Meta. I still am, but these days I get payed for it ;)
    – balpha StaffMod
    Sep 13, 2012 at 9:51

3 Answers 3

8

I have a different preference for how code-in-text could be formatted: change the background colour for that section of the text too. That's a lot clearer than quotes in my view, as well as not interfering with code which uses quotes.

11
  • If the html code allowing this is supported, it can be coded following the same principle I describe in my patch.
    – VonC
    Jul 5, 2009 at 20:06
  • > as well as not interfering with code which uses quotes. That is why I propose double or simple quotes. Now if your code uses both... it should be isolated in its own section, not within a phrase ;)
    – VonC
    Jul 5, 2009 at 20:08
  • 1
    But even if it does only use one type of quote, introducing the other one makes it more confusing to read, IMO. Background colour is visually orthogonal to the characters being displayed, which is why I think it would work well.
    – Jon Skeet
    Jul 5, 2009 at 20:09
  • Checking meta.stackexchange.com/questions/1777/… right now: I am not sure any HTML tag currently accepted would allow what you want. At least, I know my quotes won't be stripped.
    – VonC
    Jul 5, 2009 at 20:16
  • It would just be a matter of either accepting the relevant attribute for <code>, I expect. Anyway, given that this is a feature request I think it's reasonable to request the feature we (well I) think would look best, rather than one which is just a bit easier :)
    – Jon Skeet
    Jul 5, 2009 at 20:24
  • i agree with skeet here, i suggested the same thing on UV a while back and it was closed with no explanation.
    – Kip
    Jul 5, 2009 at 20:27
  • ++ for this suggestion. I hate seeing quoted code, and will actively edit it out in preference to backtick / <code> quoting. IMHO, it only leads to problems...
    – Shog9
    Jul 5, 2009 at 20:51
  • @Shog9: I assume you mean in terms of whole statements/expressions? I use backticks mostly to refer to just method/class names (usually with links). Do you mind those as well?
    – Jon Skeet
    Jul 5, 2009 at 21:19
  • Sorry, i meant that i like backtick-quoted code - it's fairly easy to read, select, copy. I don't care for "" or '' quoted code; it makes a paragraph look cluttered, and tends to be more difficult to select without catching the quotes (and as you note, can lead to confusion if the code itself contains quotes). I don't really draw a distinction between inline expressions and inline functions/symbols when formatting.
    – Shog9
    Jul 5, 2009 at 23:06
  • @Jon, @Shog9: the only reason I propose quotes or double quotes is because this is the ONLY possible addition currently possible which will not be stripped from the end result HTML. Color or border are better... but impossible for the moment. My theory is: you do not have to copy paste inline code that much anyway (so quotes do not get in the way). Code to be copied should be in its own section. Again, if color or border are possible, I would drop the quotes immediately in favor of those solutions.
    – VonC
    Jul 6, 2009 at 5:44
  • @Jon Skeet: FYI I've posted a GreaseMonkey script that does what you're asking for: meta.stackexchange.com/questions/15429/…
    – Kip
    Aug 19, 2009 at 13:17
4

I may be misunderstanding, but I dislike the idea of putting quotes around code.. It reminds me of all the times I've had to say "No, type it without the quotes.."

Perhaps the inline code could be made more visually distinct from regular text? Something like..

Border around code tag

blockquote p code{
    border:1px dashed #C8C8C8;
}

Another idea from Jonathan Sampson's question "Code-Coloring for Inline-Code in Answers" which would achieve the same thing: enable syntax highlighting for inline code, the same regular code blocks. The different colours would stand out from the rest of the text.

3
  • 1
    Yes, if it's not readable simply the stylesheet should be changed.
    – sth
    Jul 5, 2009 at 23:32
  • I like that style. Simple, not intrusive, yet stands out just that extra little bit.
    – lc.
    Jul 6, 2009 at 4:57
  • @dbr: the only reason I propose quotes or double quotes is because this is the ONLY possible addition currently possible which will not be stripped from the end result HTML. Color or border are better... but impossible for the moment.
    – VonC
    Jul 6, 2009 at 5:38
0

To test the cyclic "code sample auto-quoting" effect of CTRL+K for yourself, just:

  • install Git (or msysgit for the Windows users)

  • type "git clone http://github.com/derobins/wmd/tree/master": it will create a wmd directory.

  • open "wmd/wmd.js" in an editor and replace within the function "command.doCode()"

:

chunk.findTags(/`/, /`/);

with:

chunk.findTags(/[\"']`|`/, /`[\"']|`/);

and:

else{
    chunk.startTag = chunk.endTag="";
}

with:

        else{
            if(chunk.startTag == "`"){
                chunk.startTag = "\"`";
                chunk.endTag = "`\"";
            }
            else if(chunk.startTag == "\"`"){
                chunk.startTag = "'`";
                chunk.endTag = "`'";
            }
            else{
                chunk.startTag = chunk.endTag="";
            }
        }
  • open wmd-test.html, and start typing a few character, then repeatedly CTRL+K

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .