Skip to content

Commit

Permalink
Fix issue causing duplicated roman numerals in ID tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
seandstewart committed Mar 2, 2021
1 parent c71aaf3 commit 9d03039
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 79 deletions.
16 changes: 12 additions & 4 deletions iambic/ast/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class Scene:

@typic.cached_property
def id(self) -> NodeID:
return NodeID(parameterize(f"{self.act}-{self.type.lower()}-{self.col}"))
return NodeID(
f"{self.act}-{self.type.lower()}-{roman.numeral(self.num).lower()}"
)

@typic.cached_property
def col(self) -> str:
Expand Down Expand Up @@ -383,6 +385,10 @@ def linerange(self) -> Tuple[int, int]:
linenos = sorted((x.lineno for x in self.body if isinstance(x, Dialogue)))
return linenos[0], linenos[-1]

@typic.cached_property
def linepart(self) -> int:
return next((x.linepart for x in self.body if isinstance(x, Dialogue)), 0)

@typic.cached_property
def num_lines(self) -> int:
x, y = self.linerange
Expand All @@ -392,11 +398,13 @@ def num_lines(self) -> int:

@typic.cached_property
def id(self) -> NodeID:
return NodeID(
uri = (
f"{self.scene}-{self.persona}-{self.type.lower()}-"
f"{'{0}-{1}'.format(*self.linerange)}"
f"-{self.index}"
f"{'-'.join(map(str, self.linerange))}"
)
if self.linepart:
uri += f"-{roman.numeral(self.linepart).lower()}"
return NodeID(uri)


@typic.klass(unsafe_hash=True, slots=True)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "iambic"
version = "2.4.0"
version = "2.4.1"
description = "Data extraction and rendering library for Shakespearean text."
authors = ["Sean Stewart <[email protected]>"]
license = "MIT"
Expand Down
86 changes: 43 additions & 43 deletions tests/static/foo-rendered.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@
???+ "Character Navigation"

=== "Prologue"
- [Foo ⇒ 💬](#prologue-0-foo-speech-1-1-3)
- [A Bar ⇒ 💬](#prologue-0-a-bar-speech-2-2-5)
- [Bar's Foo ⇒ 💬](#prologue-0-bar-s-foo-speech-3-3-7)
- [Foo ⇒ 💬](#prologue-0-foo-speech-1-1)
- [A Bar ⇒ 💬](#prologue-0-a-bar-speech-2-2)
- [Bar's Foo ⇒ 💬](#prologue-0-bar-s-foo-speech-3-3)

=== "I: Prologue"
- [Bar ⇒ 💬](#act-i-prologue-10-bar-speech-4-4-13)
- [Bar ⇒ 💬](#act-i-prologue-10-bar-speech-4-4)

=== "Intermission"

=== "I: i"
- [Foo ⇒ 💬](#act-i-scene-i-i-foo-speech-5-5-19)
- [Bar ⇒ 💬](#act-i-scene-i-i-bar-speech-6-6-22)
- [Foo ⇒ 💬](#act-i-scene-i-foo-speech-5-5)
- [Bar ⇒ 💬](#act-i-scene-i-bar-speech-6-6)

=== "I: Epilogue"
- [Foo ⇒ 💬](#act-i-epilogue-35-foo-speech-8-8-38)
- [Bar ⇒ 💬](#act-i-epilogue-35-foo-bar-speech-9-9-41)
- [Foo ⇒ 💬](#act-i-epilogue-35-foo-speech-8-8)
- [Bar ⇒ 💬](#act-i-epilogue-35-foo-bar-speech-9-9)


??? "Character Navigation (Grid)"

| Dramatis Personae | First Appearance | Lines | Prologue | I: Prologue | Intermission | I: i | I: Epilogue |
|---------------------|--------------------|---------|------------------------------------------|--------------------------------------------|----------------|------------------------------------------|------------------------------------------------|
| Foo | 2 | 6 | [💬](#prologue-0-foo-speech-1-1-3) | | | [💬](#act-i-scene-i-i-foo-speech-5-5-19) | [💬](#act-i-epilogue-35-foo-speech-8-8-38) |
| A Bar | 4 | 1 | [💬](#prologue-0-a-bar-speech-2-2-5) | | | | |
| Bar's Foo | 6 | 1 | [💬](#prologue-0-bar-s-foo-speech-3-3-7) | | | | |
| Bar | 12 | 4 | | [💬](#act-i-prologue-10-bar-speech-4-4-13) | | [💬](#act-i-scene-i-i-bar-speech-6-6-22) | [💬](#act-i-epilogue-35-foo-bar-speech-9-9-41) |
| Dramatis Personae | First Appearance | Lines | Prologue | I: Prologue | Intermission | I: i | I: Epilogue |
|---------------------|--------------------|---------|----------------------------------------|-----------------------------------------|----------------|-------------------------------------|---------------------------------------------|
| Foo | 2 | 6 | [💬](#prologue-0-foo-speech-1-1) | | | [💬](#act-i-scene-i-foo-speech-5-5) | [💬](#act-i-epilogue-35-foo-speech-8-8) |
| A Bar | 4 | 1 | [💬](#prologue-0-a-bar-speech-2-2) | | | | |
| Bar's Foo | 6 | 1 | [💬](#prologue-0-bar-s-foo-speech-3-3) | | | | |
| Bar | 12 | 4 | | [💬](#act-i-prologue-10-bar-speech-4-4) | | [💬](#act-i-scene-i-bar-speech-6-6) | [💬](#act-i-epilogue-35-foo-bar-speech-9-9) |

??? "Dramatis Personae"

Expand All @@ -70,17 +70,17 @@
*Enter FOO* <a class="headerlink" href="#prologue-0-entrance-1" title="Permanent link">👁️‍🗨️</a>
{: id=prologue-0-entrance-1 }

**Foo** <a class="headerlink" href="#prologue-0-foo-speech-1-1-3" title="Permanent link">(1, 1)</a>
**Foo** <a class="headerlink" href="#prologue-0-foo-speech-1-1" title="Permanent link">(1, 1)</a>
Bar.
{: id=prologue-0-foo-speech-1-1-3 }
{: id=prologue-0-foo-speech-1-1 }

**A Bar** <a class="headerlink" href="#prologue-0-a-bar-speech-2-2-5" title="Permanent link">(2, 2)</a>
**A Bar** <a class="headerlink" href="#prologue-0-a-bar-speech-2-2" title="Permanent link">(2, 2)</a>
Bar!
{: id=prologue-0-a-bar-speech-2-2-5 }
{: id=prologue-0-a-bar-speech-2-2 }

**Bar's Foo** <a class="headerlink" href="#prologue-0-bar-s-foo-speech-3-3-7" title="Permanent link">(3, 3)</a>
**Bar's Foo** <a class="headerlink" href="#prologue-0-bar-s-foo-speech-3-3" title="Permanent link">(3, 3)</a>
Foo!
{: id=prologue-0-bar-s-foo-speech-3-3-7 }
{: id=prologue-0-bar-s-foo-speech-3-3 }


*Exeunt* <a class="headerlink" href="#prologue-0-exit-8" title="Permanent link">👁️‍🗨️</a>
Expand All @@ -96,50 +96,50 @@ Foo!
*Enter BAR* <a class="headerlink" href="#act-i-prologue-10-entrance-11" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-prologue-10-entrance-11 }

**Bar** <a class="headerlink" href="#act-i-prologue-10-bar-speech-4-4-13" title="Permanent link">(4, 4)</a>
**Bar** <a class="headerlink" href="#act-i-prologue-10-bar-speech-4-4" title="Permanent link">(4, 4)</a>
*\[Aside]*
Foo.
{: id=act-i-prologue-10-bar-speech-4-4-13 }
{: id=act-i-prologue-10-bar-speech-4-4 }


### INTERMISSION {: id=intermission }

### SCENE I. A place of meeting. {: id=act-i-scene-i-i }
### SCENE I. A place of meeting. {: id=act-i-scene-i }


*Enter FOO and BAR* <a class="headerlink" href="#act-i-scene-i-i-entrance-17" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-scene-i-i-entrance-17 }
*Enter FOO and BAR* <a class="headerlink" href="#act-i-scene-i-entrance-17" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-scene-i-entrance-17 }

**Foo** <a class="headerlink" href="#act-i-scene-i-i-foo-speech-5-5-19" title="Permanent link">(5, 5)</a>
**Foo** <a class="headerlink" href="#act-i-scene-i-foo-speech-5-5" title="Permanent link">(5, 5)</a>
*\[To BAR]*
Bar.
{: id=act-i-scene-i-i-foo-speech-5-5-19 }
{: id=act-i-scene-i-foo-speech-5-5 }

**Bar** <a class="headerlink" href="#act-i-scene-i-i-bar-speech-6-6-22" title="Permanent link">(6, 6)</a>
**Bar** <a class="headerlink" href="#act-i-scene-i-bar-speech-6-6" title="Permanent link">(6, 6)</a>
Foo.
{: id=act-i-scene-i-i-bar-speech-6-6-22 }
{: id=act-i-scene-i-bar-speech-6-6 }

**Foo** <a class="headerlink" href="#act-i-scene-i-i-foo-speech-7-7-24" title="Permanent link">(7, 7)</a>
**Foo** <a class="headerlink" href="#act-i-scene-i-foo-speech-7-7-i" title="Permanent link">(7, 7)</a>
Bar. ...
{: id=act-i-scene-i-i-foo-speech-7-7-24 }
{: id=act-i-scene-i-foo-speech-7-7-i }


*Thunder and lightning, very very frightening* <a class="headerlink" href="#act-i-scene-i-i-direction-25" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-scene-i-i-direction-25 }
*Thunder and lightning, very very frightening* <a class="headerlink" href="#act-i-scene-i-direction-25" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-scene-i-direction-25 }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... Bar! ...

**Bar** <a class="headerlink" href="#act-i-scene-i-i-bar-speech-7-7-28" title="Permanent link">(7, 7)</a>
**Bar** <a class="headerlink" href="#act-i-scene-i-bar-speech-7-7-iii" title="Permanent link">(7, 7)</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... Foo. ...
{: id=act-i-scene-i-i-bar-speech-7-7-28 }
{: id=act-i-scene-i-bar-speech-7-7-iii }

**Foo** <a class="headerlink" href="#act-i-scene-i-i-foo-speech-7-7-30" title="Permanent link">(7, 7)</a>
**Foo** <a class="headerlink" href="#act-i-scene-i-foo-speech-7-7-iv" title="Permanent link">(7, 7)</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... Bar.
{: id=act-i-scene-i-i-foo-speech-7-7-30 }
{: id=act-i-scene-i-foo-speech-7-7-iv }


*A long stage direction that goes on forever and says far to much to be reasonable. So much so that it takes up more than two lines, which is just ridiculous. I mean seriously, why? Why write so much for one stage direction? For what purpose?* <a class="headerlink" href="#act-i-scene-i-i-direction-31" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-scene-i-i-direction-31 }
*A long stage direction that goes on forever and says far to much to be reasonable. So much so that it takes up more than two lines, which is just ridiculous. I mean seriously, why? Why write so much for one stage direction? For what purpose?* <a class="headerlink" href="#act-i-scene-i-direction-31" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-scene-i-direction-31 }


### EPILOGUE {: id=act-i-epilogue-35 }
Expand All @@ -148,13 +148,13 @@ Bar. ...
*Enter FOO and BAR* <a class="headerlink" href="#act-i-epilogue-35-entrance-36" title="Permanent link">👁️‍🗨️</a>
{: id=act-i-epilogue-35-entrance-36 }

**Foo** <a class="headerlink" href="#act-i-epilogue-35-foo-speech-8-8-38" title="Permanent link">(8, 8)</a>
**Foo** <a class="headerlink" href="#act-i-epilogue-35-foo-speech-8-8" title="Permanent link">(8, 8)</a>
*\[Reads]*
Foo.
{: id=act-i-epilogue-35-foo-speech-8-8-38 }
{: id=act-i-epilogue-35-foo-speech-8-8 }

**Foo & Bar** <a class="headerlink" href="#act-i-epilogue-35-foo-bar-speech-9-9-41" title="Permanent link">(9, 9)</a>
**Foo & Bar** <a class="headerlink" href="#act-i-epilogue-35-foo-bar-speech-9-9" title="Permanent link">(9, 9)</a>
Together!
{: id=act-i-epilogue-35-foo-bar-speech-9-9-41 }
{: id=act-i-epilogue-35-foo-bar-speech-9-9 }


Loading

0 comments on commit 9d03039

Please sign in to comment.