Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 11-30-2015, 10:04 AM   #1
tiandijie
Member
tiandijie began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Sep 2015
Device: Kindle Voyage
a little problem with code formatting

Hi sigil fans, I'm having a little dumb question here and looking for some slutions. I'm creating a book about html, and I need to show some code examples in my book, like <p style="background-color:yellow;">XXXX</p>. the problem is sigil will just treat them as general code and execute them, so I can only see “XXXX” in book view with yellow background. I tried to wrap them with code tag, like:
<code>
<p style="background-color:yellow;">XXXX</p>
</code>

but this does not work. For now I should add some random notations between tags so Sigil won't execute them. Does anyone have some better ideas?
tiandijie is offline   Reply With Quote
Old 11-30-2015, 11:00 AM   #2
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,365
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
If you paste html code into book view, it will do the escaping necessary to render them. In code view you would have to use entities manually to represent the the < and > characters. Either way, you will have to use styles to do any colors and/or highlighting.

There is no handy-dandy tag to present code in xhtml (in all renderers). Those are typically forum or blog (or other rendering engine) plugins that allow posts to present code in an easy manner (on THAT particular platform).
DiapDealer is offline   Reply With Quote
Advert
Old 11-30-2015, 11:17 AM   #3
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,641
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by tiandijie View Post
Hi sigil fans, I'm having a little dumb question here and looking for some slutions. I'm creating a book about html, and I need to show some code examples in my book, like <p style="background-color:yellow;">XXXX</p>. the problem is sigil will just treat them as general code and execute them, so I can only see “XXXX” in book view with yellow background. I tried to wrap them with code tag, like:
<code>
<p style="background-color:yellow;">XXXX</p>
</code>

but this does not work. For now I should add some random notations between tags so Sigil won't execute them. Does anyone have some better ideas?
Do the following:

1. In your .xhtml file write:

Code:
<div class="code">
    <pre>
         &lt;p class="background"&gt;XXX&lt;/p&gt;
    </pre>
</div>
2. In your .css file write:

Code:
.code {
   font-family: "monospace"; /* This wouldn't be necessary if you use the <pre> tag but... */
   background: #eee;
   font-size: 1.2em; /* change the font size if you wish */
   font-weight: bold; /* change this to normal if you wish */
   padding: 0 1em;
   border: 1px dotted;
}
This is how it looks in Sigil:

Click image for larger version

Name:	Image1.png
Views:	164
Size:	71.4 KB
ID:	144194

Below I attach the respective epub so you can understand better all the things.

Regards
Rubén
Attached Files
File Type: epub Code Example.epub (2.2 KB, 122 views)

Last edited by RbnJrg; 11-30-2015 at 11:25 AM.
RbnJrg is offline   Reply With Quote
Old 12-01-2015, 07:08 AM   #4
Notjohn
mostly an observer
Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.
 
Posts: 1,518
Karma: 987654
Join Date: Dec 2012
Device: Kindle
I used Freebits for this purpose:

http://www.freebits.co.uk/convert-ht...e-to-text.html

(I didn't know about pasting into Book View! Indeed, it was probably before Hitch turned me on to epub.)
Notjohn is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PDF to MOBI formatting source code redhead_cz Conversion 2 02-10-2013 04:33 PM
Formatting for documentation source code Halo Development 1 08-14-2011 09:39 PM
Help formatting Source Code frios ePub 3 07-15-2011 08:06 AM
Formatting, code, simple help needed panda6855 Sigil 43 01-13-2011 06:37 PM
would someone kindly explain this formatting code Book IMP 2 07-03-2009 10:53 PM


All times are GMT -4. The time now is 12:38 AM.


MobileRead.com is a privately owned, operated and funded community.