I am currently creating a book layout with inline code and code-blocks.
For those code parts, i would like to add a background-color. It should handle code similar to the way it is displayed on StackExchange.
As there is no option in paragraph-styles, that would add a background, I tried to use paragraph rules, underline rules, strikethrough rules and some other experimental approaches.
The striketrough rules are displayed above the text, making it completely useless for this purpose.
Underline rules are displayed under the text, which makes it possible to use it as a background. The problem is, that it depends on the character-length. That makes it possible to use it over lines that have an automatic line-break.
The problem is, that you can’t add margins to it and that you can’t insert a background with a fixed width.
Paragraph rules are pretty close to a solution. You can determine, if you want the line above, or below your text, you can add margins and the line fills the whole width of the block. The problem here is, that it is a paragraph line, meaning that it adds a rule for the whole paragraph instead of each line. That is no problem if every paragraph is only one line high, but if a paragraph that includes multiple lines, you end up with a gap in the background. I could add a forced line-break here, but I would like to avoid that.
A solution would be, if I could add a forced line-break on the end of each line through a GREP-style, but I haven’t seen any way to add a character this way.
I am using character styles for inline Code. Underline rules seems to be the most appropriate way to go here. The problem is, that I am massing margins here. If I add a space on the beginning and the end of the inline code, I end up with a nice result, but that means I have to add characters to the text, which I would like to avoid and it would not work on the beginning and the end of a line-break, because inDesign deletes the character if it is not needed.
I am searching a way to add some space before and at the end of the inline code.
So, that would be it. I am searching solutions to this problem for a long time now, so any ideas would be appreciated.
Oh and sorry for the crappy image quality. The missing retina display support of inDesign made it possible.