What's the best way to represent a stage scrip

2020-02-20 07:02发布

问题:

I have a sketch that I want to put up on my website, and I also intend to write a short play at some point which I'd also want to make freely available.

I'm trying to work out the best way of representing this in HTML. I basically need two columns - one for the character speaking, and one for the text. Each speech obviously needs to line up with the speaker though. In other words, something like this:

    Jeff        This sure is a nice website we've got now.

    Joel        It certainly is. By the way, working at FogCreek rocks.

    Jeff        Of course it does. Have you played Rock Band yet? It's
                 a lot of fun.

(Well it's better than lorem ipsum...)

I know how I could do this with HTML tables (with one table row per speech) but that seems pretty ugly, and everyone certainly seems to be keen on using CSS to represent non-tabular data. I can't see how this really counts a tabular data - my use of "row" and "column" earlier was to do with the layout rather than the fundamental data.

So, any ideas? I think most of the script websites I've seen (not many, admittedly) either use <pre> like my example above, or don't bother trying to keep the normal script format, instead just prefixing each paragraph with the speaker's name. (See the podcast wiki for an example of this style.) I'm having trouble working out even what HTML elements I should be using to represent this, frankly - a dictionary definition list with the speaker as the term and the speech as the definition is probably the closest I've thought of, but that feels like abuse.

回答1:

I second the heresy :-)

Always good to consider CSS before resorting to tables - but often tables really are the best fit. It looks like it in this case.

The only additional consideration would be accessibility. I've heard that tables make it harder for text reader software to process tables, but I don't see why this would be the case (feel free to comment here if you know more).

One other thing - I presume you'd be holding the raw data in some other format first - perhaps a database, or xml or some other structured text?

In any case, getting it into an xml format and tranforming that to html with xslt can be quite liberating when it comes to playing with this stuff.



回答2:

More proper (semantically) and shorter would be to use definition lists:

dl {
  overflow: hidden;
}

dl dt {
  float: left;
  width: 30%;
}

dl dd {
  float: left;
  width: 70%;
}
<dl>
  <dt>Jeff</dt>
  <dd>This sure is a nice website we've got now.</dd>
  <dt>Joel</dt>
  <dd>It certainly is. By the way, working at FogCreek rocks.</dd>
  <dt>Jeff</dt>
  <dd>Of course it does. Have you played Rock Band yet? It's a lot of fun.</dd>
</dl>



回答3:

I'd say

<dialog>
  <dt>Jeff
  <dd>This sure is a nice website we've got now.
  <dt>Joel
  <dd>It certainly is. By the way, working at FogCreek rocks.
  <dt>Jeff
  <dd>Of course it does. Have you played Rock Band yet? It's a lot of fun.
</dialog>

as defined in HTML5.

Of course, you'll need a <script>document.createElement('dialog');</script> to get IE to do something sensible and a dialog { display:block; } in your CSS to get it to work completely.



回答4:

My favourite example of marking up something like this is one of Tantek's XHTML compounds http://tantek.com/presentations/2005/03/elementsofxhtml/ (check out the conversation bit)

In summary it goes like so:

<ol>
  <li><cite>Jeff</cite>
    <blockquote><p>This sure is a nice website we've got now.</p><blockquote>
  </li>
  <li><cite>Joel</cite>
    <blockquote><p>It certainly is. By the way, working at FogCreek rocks.</p></blockquote>
  </li>
  ...etc...
</ol>

Not sure how you'd mark up stage directions etc... Maybe you'll end up creating a new microformat :)

Also that markup has some ideal CSS hooks, with discrete LInes unlike a definition list.



回答5:

Please avoid the "sledge hammer syndrome" (if your only tool is a hammer, you try to treat every problem like a nail). HTML is a representation language, not a source language.

So my suggestion is to write the play in something which can represent your thoughts best (not necessarily XML) and then convert that to HTML. For my own works, I'm using a recursive XML parser which can fall out of XML parsing for certain elements:

<content><<Hello,>> Forne smiled and thought: <<T Idiot.>></content>

My parser will invoke a custom parser to parse the content of <content>. In my case, it will create an intermediate XML tree:

<content><say>Hello,</say> <char>Forne</char> smiled and thought: <think>Idiot.</think></content>

This tree is then converted into HTML, TeX, PDF, whatever.

[EDIT] My strategy to come up with a compact language works like this: I start with XML. After a while, I look at the XML and try to see patterns. Then I think how I could express these patterns in a more compact way 1.) as XML, 2.) as XML text (with custom markup) and 3.) as something else entirely. When an idea hits me, I write a parser for the new format.

Frankly, writing parsers which can turn something into XML for automatic background processing is a minor task, today.



回答6:

IMO that actually is tabular data. First column is speaker, second column is text.

If you want to be fashionable and aggressively eschew tables, though, what I believe is compliant with what the Web mavens are dictating this season is a structure like:

<div class="play">
  <div class="line">
    <div class="speaker">Jeff</div>
    <div class="text">This sure is a nice website we've got now. </div>
  </div>
  <div class="line">
    <div class="speaker">Joel</div>
    <div class="text">It certainly is. By the way, working at FogCreek rocks.</div>
  </div>
</div>

Then you control how that lays out with appropriate CSS.

If it looks like you're basically writing XML and using CSS to specify how it lays out, well, that's because that's what the Web mavens believe you should be doing, AFAICT.



回答7:

I would use headers and paragraphs.

With the following styles it would arrange as you presented it:

.play h2 {
  float: left;
  clear: left;
  width: 100px;
  margin: 0;
}

.play p {
  margin-left: 100px;
}
<div class="play">
  <h2>Jeff</h2>
  <p>This sure is a nice website we've got now.</p>

  <h2>Joel</h2>
  <p>It certainly is. By the way, working at FogCreek rocks.</p>

  <h2>Jeff</h2>
  <p>Of course it does. Have you played Rock Band yet? It's<br /> a lot of fun.</p>
</div>



回答8:

Tables is the way to go.

Anything else like messing around with <div>s and css or XSLT is just reinventing the <table> but with a c**p syntax.

I would go for three or four fixed width colums. (Any non-trivial play is going to need stage directions, special effects, sound effects etc.).



回答9:

You're not going to get a definitive answer to this question as HTML has many gaps, one of which is this - there are some very solid articles dotted around the web about his subject and a good place to start would be Bruce Lawson's article from 2006.

Considering that there is no answer to the question, the best we can do is look at what elements that are available to us and make our own compromises based upon our (and the communities) interpretation of the guidelines.

I personally like the cite/blockquote and data list route. I know that data lists smack of none semantic markup, but I truly believe that the intent of data lists isn't to list data definitions purely in a dictionary fashion, but to pair data where uls and ols can't.

I've spent a lot of time thinking about semantics, and one thing I (as well as most others in the field) am sure of when looking at all questions of markup is that tables are not the answer to 99.9% of markup questions (if it's not tabular data where you can use th, caption then tables should really be dropped from your inventory). That said, I would also say that exclusively using divs is also probably not the right answer.

I very much doubt that the up-votes in this question will reflect the best approach, but will more likely reflect an agreement to the approach base upon the voters current knowledge and use of HTML.



回答10:

HTML 5.2 recommendation for conversations

authors are encouraged to mark up conversations using p elements and punctuation. Authors who need to mark the speaker for styling purposes are encouraged to use span or b. Paragraphs with their text wrapped in the i element can be used for marking up stage directions.

Example conversation with minimal markup

<article class=stage-script>
  <h1>Water Cooler Talk at FogCreek</h1>

  <p><b>Jeff</b> This sure is a nice website we've got now.

  <p><b>Joel</b> It certainly is. By the way, working at FogCreek rocks.

  <p><b>Jeff</b> Of course it does. Have you played Rock Band yet? It's a lot of fun.

  <p><i>Joel and Jeff walk into the sunset</i>
</article>

CSS for the conversation

.stage-script > p > b:first-child {
    display: inline-block;
    width: 5em;
}
.stage-script > p > b:first-child::after {
    content: ':';
}


回答11:

I would just use div elements in this case, with nice classes describing the domain. You could argue up and down about using all kinds of HTML elements that give a better semantic meaning of intent, but for instance in the case of the dialog element, that is not intended for writing dialogs between characters in a play, it is however intended to present a dialog box to the user for interacting. But the fact that you can change and style that element to your hearts desire in CSS is nifty - but I would not recommend doing so.

The reason for that is simply that unless you are careful, you override that behavior and appearance for every such element. Let's say this is an interactive application for playwrights, you may want to include dialog boxes in addition to the "dialog" in the play.

I propose this solution:

.character{
  display: block;
  float: left;
}

.line{
  margin-bottom: 20pt;
  width: 400px;
  margin-left: 50pt;
}

With the following HTML:

<div class="character">Jeff</div>
<div class="line">This sure is a nice website we've got now.</div>
<div class="character">Joel</div>
<div class="line"> It certainly is. By the way, working at FogCreek rocks.</div>
<div class="character">Jeff</div>
<div class="line">Of course it does. Have you played Rock Band yet? 
  <br/>It's a lot of fun.</div>

Running JSFiddle: https://jsfiddle.net/quz9cj2f/6/

Now you can actually implement some standard play formatting, that I nicked from this place: http://ptfaculty.gordonstate.edu/lking/CPF_play_formatting2.pdf

.play {
  font-family: courier;
}
.play{
  margin-top: 1in;
  margin-left: 1.5in;
  margin-right: 1in;
  margin-bottom: 1in;
}
.character {
  display: block;
  margin-left: 4in;
  text-transform: uppercase;
}
.direction:before{
  margin-left: 2.75in;
  content: "(";
}
.direction:after{
  content: ")";
}
.line {
  margin-bottom: .3in;
}

With this HTML:

<div class="play">
  <div class="character">Jeff</div>
  <div class="direction">JEFF is enthusiastic!</div>
  <div class="line">This sure is a nice website we've got now.</div>
  <div class="character">Joel</div>
  <div class="direction">Jumping continuously</div>
  <div class="line"> It certainly is. By the way, working at FogCreek rocks.</div>
  <div class="character">Jeff</div>
  <div class="line">Of course it does. Have you played Rock Band yet?
    <br/>It's a lot of fun.</div>
</div>

Working JSFiddle: https://jsfiddle.net/quz9cj2f/9/

Or you could go all in and use CSS attribute selectors and create a custom attributes for the meta information:

.play {
  font-family: courier;
}
.play{
  margin-top: 1in;
  margin-left: 1.5in;
  margin-right: 1in;
  margin-bottom: 1in;
}
.character {
  display: block;
  margin-left: 4in;
  text-transform: uppercase;
}
.line[direction]:before{
  margin-left: 2.75in;
  content: "(" attr(direction) ")";
  display: block;
}

.line {
  margin-bottom: .3in;
}

Now you have gotten rid of the extra elements, and added the meta info as attributes - now you could quite easy transform this from some kind of nice data structure from JSON or XML or other interchange formats into this:

<div class="play">
  <div class="character">Jeff</div>
  <div direction="Enthusiastic" class="line">This sure is a nice website we've got now.</div>
  <div class="character">Joel</div>
  <div direction="Shaking his head" class="line"> It certainly is. By the way, working at FogCreek rocks.</div>
  <div class="character">Jeff</div>
  <div class="line">Of course it does. Have you played Rock Band yet?
    <br/>It's a lot of fun.</div>
</div>

https://jsfiddle.net/quz9cj2f/11/



回答12:

If you want to do it semantically, I would use labels, something like:

<div class="script">
<label for="Jeff1">Jeff<label>
<div id="Jeff1">
  <p>This sure is a nice website we've got now.</p>
</div>

<label for="Joel1">Joel</label>
<div id="Joel1">
  <p>It certainly is.</p>
  <p>By the way, working at FogCreek rocks.</p>
</div>

<label for="Jeff2">Jeff</label>
<div id="Jeff2">
  <p>Of course it does.</p>
  <p>Have you played Rock Band yet? It's a lot of fun.</p>
</div>

</div>

That degrades pretty nicely and I think the label is a bit more appropriate for what you're trying to do. And then, in your style sheet, I would style it something like Eran Galperin's example CSS.

The other suggestion I would have, if you're serious about this, would be to look further into how dead tree scripts are written and do your utmost to preserve their style. This will help ensure that it looks familiar (read professional) to your audience.