Skip to content

Commit

Permalink
Merge pull request #129 from nert-gu/xposition-issues
Browse files Browse the repository at this point in the history
Interlinear glosses
  • Loading branch information
nschneid authored Jul 30, 2018
2 parents 69bafbe + 1fe8814 commit 7123278
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 5 deletions.
2 changes: 1 addition & 1 deletion testproject/testproject/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
WIKI_URL_CASE_SENSITIVE = True
WIKI_URL_CONFIG_CLASS = 'wiki.plugins.metadata.urls.XpositionURLPatterns'

WIKI_MARKDOWN_HTML_WHITELIST = ['sub', 'sup', 'hr', 'u']
WIKI_MARKDOWN_HTML_WHITELIST = ['sub', 'sup', 'hr', 'u', 'br']

# To make deployment happy
SECURE_BROWSER_XSS_FILTER = True
Expand Down
51 changes: 49 additions & 2 deletions wiki/plugins/macros/mdx/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from wiki.plugins.macros import settings
from wiki.plugins.metadata import models
from wiki.models import Article
from django.utils.html import escape, mark_safe, format_html

# See:
# http://stackoverflow.com/questions/430759/regex-for-managing-escaped-characters-for-items-like-string-literals
Expand Down Expand Up @@ -192,7 +193,7 @@ def ss(self, *args):
args={'name': _('Name of supersense/construal label'), 'class': _('optional class')}
)

def exref(self, id, page):
def exref(self, id, page, *args):
my_title = self.markdown.article.current_revision.title
ref_title = page
ref_slug = page
Expand All @@ -216,7 +217,7 @@ def exref(self, id, page):
args={'id': _('id of example'), 'page': _('title of page example is on')}
)

def ex(self, id, sent, label=None):
def ex(self, id, sent, label=None, *args):
if label:
return f'<span id="{id}" class="example">{sent}&nbsp;<span class="exlabel">{label}</span></span>'
return f'<span id="{id}" class="example">{sent}&nbsp;<a href="#{id}" class="exlabel">{id}</a></span>'
Expand All @@ -228,6 +229,52 @@ def ex(self, id, sent, label=None):
args={'id': _('id of example'), 'sent': _('full sentence in double quotes'), 'label': _('string to display after ex. (if not id)')}
)

GLOSS_RE = re.compile('^\{(?P<tok_gloss>[^}]*?)\}')
def gex(self, id, sent, sent_gloss='', label=None, *args):
columns = []
while len(sent)>0:
gloss = self.GLOSS_RE.match(sent)
if gloss:
word_gloss = gloss.group('tok_gloss')
sent = sent[len(gloss.group()):]
if '||' in word_gloss:
xs = word_gloss.split('||')
else:
xs = word_gloss.split()
xs = [escape(x) for x in xs]
column = '<div class="gll">'+'<br />'.join(xs)+'</div>'
else:
end = sent.index('{') if '{' in sent else len(sent)
word_gloss = sent[:end]
sent = sent[len(word_gloss):]
if word_gloss.strip():
column = '<div class="gll">' + escape(word_gloss.strip()) + '</div>'
else:
column = ''
columns.append(column)
interlinear = ''.join(columns)
interlinear = format_html(f'''<span id="{id}" class="example">
<div class="interlinear">
<p class="gloss">
{interlinear}
</p>
<p class="translation">{{}}&nbsp;<a href="#{{}}" class="exlabel">{{}}</a></p>
</div></span>
''', sent_gloss, id, id)
return interlinear
# meta data
gex.meta = dict(
short_description=_('Create a Glossed Example'),
help_text=_('Create an example sentence word and sentence translation displayed on separate lines.'),
example_code='[gex 001 '
'"{L\' the}{éléphant elephant} {gris gray} est<br> {[p fr/dans Locus]||[p en/in Locus]} {la voiture||the car}." '
'"The gray elephant is in the car."]',
args={'id': _('id of example'),
'sent': _('full sentence in double quotes with glossed tokens as {token||gloss}'),
'sent_gloss': _('glossed translation of sentence'),
'label': _('string to display after ex. (if not id)')}
)


def link(t, l, clazz):
return '<a href="' + l + '" class="' + clazz + '">' + t + '</a>'
1 change: 1 addition & 0 deletions wiki/plugins/macros/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'toc',
'wikilink',
'ex',
'gex',
'p',
'pspecial',
'ss',
Expand Down
25 changes: 25 additions & 0 deletions wiki/plugins/metadata/migrations/0042_auto_20180728_2014.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-07-29 00:14
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('metadata', '0041_auto_20180724_0024'),
]

operations = [
migrations.AlterField(
model_name='corpus',
name='description',
field=models.CharField(blank=True, help_text='Include number of tokens and basic statistics', max_length=200, verbose_name='Description'),
),
migrations.AlterField(
model_name='metadatarevision',
name='description',
field=models.CharField(max_length=300),
),
]
4 changes: 2 additions & 2 deletions wiki/plugins/metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Meta():
class MetadataRevision(RevisionPluginRevision):
template = models.CharField(max_length=100, default="wiki/view.html", editable=False)
name = models.CharField(max_length=100, db_index=True)
description = models.CharField(max_length=200)
description = models.CharField(max_length=300)
article_revision = models.OneToOneField(ArticleRevision, null=True, related_name='metadata_revision')

unique_together = None # can be overriden by subclasses
Expand Down Expand Up @@ -850,7 +850,7 @@ class Corpus(SimpleMetadata):
version = models.CharField(max_length=200, null=True, validators=[version_validator], verbose_name="Version")
url = models.URLField(max_length=200, blank=True, verbose_name="URL")
genre = models.CharField(max_length=200, blank=True, verbose_name="Corpus Genre")
description = models.CharField(max_length=300, blank=True, verbose_name="Description",
description = models.CharField(max_length=200, blank=True, verbose_name="Description",
help_text="Include number of tokens and basic statistics")
languages = models.CharField(max_length=200, null=True, verbose_name="Language(s)")

Expand Down
23 changes: 23 additions & 0 deletions wiki/plugins/metadata/static/wiki/css/metadata.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,26 @@ http://nicolasgallagher.com/jump-links-and-viewport-positioning/demo/#method-D *
-moz-background-clip: padding;
background-clip: padding-box;
}

// interlinear.css 2/28/2009 Kevin B. McGowan <[email protected]>

// this first class is thorougly unnecessary unless you want to
// be able to manipulate all of the glls in a given interlinear
.interlinear {
padding-left: 20px;
}

p.gloss, p.gl {
margin-bottom: 0px;
}

div.gll {
valign: top;
display: inline-table;
padding-right: 10px;
margin-bottom: 0px;
}

p.translation, p.trans, p.glt {
margin-top: 0px;
}

0 comments on commit 7123278

Please sign in to comment.