Skip to content

Commit

Permalink
Merge pull request #50 from edgarcosta/copycode
Browse files Browse the repository at this point in the history
enabling copyign snippets for groups
  • Loading branch information
jenpaulhus authored Aug 13, 2024
2 parents bd903ea + 538430e commit 6fb8db6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
16 changes: 13 additions & 3 deletions lmfdb/groups/abstract/web_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2691,10 +2691,20 @@ def create_snippet(self,item):
else: # not currrently used in groups
lines = code[item][L]
prompt = code['prompt'][L] if 'prompt' in code and L in code['prompt'] else L
class_str = " ".join([L,'nodisplay','code','codebox'])
col_span_val = '"6"'
class_str = " ".join([L,'nodisplay','codebox'])
col_span_val = '"6"'
for line in lines:
snippet_str = snippet_str + f'<tr><td colspan={col_span_val}><div class="{class_str}"><span class="raw-tset-copy-btn" onclick="copyTextOf(this)"><img alt="Copy content" class="tset-icon"></span> {prompt}:&nbsp;{line}<div style="margin: 0; padding: 0; height: 0;">&nbsp;</div></div></td></tr>'
snippet_str += f"""
<tr>
<td colspan={col_span_val}>
<div class="{class_str}">
<span class="raw-tset-copy-btn" onclick="copycode(this)"><img alt="Copy content" class="tset-icon"></span>
<span class="prompt">{prompt}:&nbsp;</span><span class="code">{line}</span>
<div style="margin: 0; padding: 0; height: 0;">&nbsp;</div>
</div>
</td>
</tr>
"""
return snippet_str


Expand Down
9 changes: 8 additions & 1 deletion lmfdb/static/raw_typeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ function copyTextOf(elt) {
);
}

function copySibling(elt, filter) {
copyTextOf($(elt).parent().children(filter).first());
}

function copyrawcontainer(elt) {
copyTextOf($(elt).parent().children("textarea.raw-container").first());
copySibling(elt, "textarea.raw-container");
}
function copycode(elt) {
copySibling(elt, "span.code");
}


Expand Down
14 changes: 12 additions & 2 deletions lmfdb/templates/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,23 @@ body.intro #sidebar a.intro { background: {{ color.sidebar_bkg_highlight }}; }
height: 0px;
}

.code {
.code, .prompt {
font-family: monospace;
white-space: pre;
}

.code {
margin: 2px;
margin-right: 20px;
margin-left: 0px;
}

.prompt {
margin: 2px;
margin-right: 0px;
}


.nodisplay {
display: None;
}
Expand Down Expand Up @@ -1952,7 +1963,6 @@ div.codebox {
border-radius: 5px;
background-color: {{color.knowl_background}};
box-shadow: 3px 3px 3px {{color.knowl_shadow}};
white-space: pre;
}


Expand Down

0 comments on commit 6fb8db6

Please sign in to comment.