Commit a8d30c5d by stv

Remove circuit-schematic integration from wiki

parent d77f31dd
...@@ -1987,23 +1987,6 @@ function update_schematics() { ...@@ -1987,23 +1987,6 @@ function update_schematics() {
} }
window.update_schematics = update_schematics; window.update_schematics = update_schematics;
// add ourselves to the tasks that get performed when window is loaded
function add_schematic_handler(other_onload) {
return function() {
// execute othe onload functions first
if (other_onload) other_onload();
update_schematics();
}
}
// ask each schematic input widget to update its value field for submission
function prepare_schematics() {
var schematics = $('.schematic');
for (var i = schematics.length - 1; i >= 0; i--)
schematics[i].schematic.update_value();
}
schematic = (function() { schematic = (function() {
var background_style = 'rgb(220,220,220)'; var background_style = 'rgb(220,220,220)';
var element_style = 'rgb(255,255,255)'; var element_style = 'rgb(255,255,255)';
...@@ -6196,4 +6179,3 @@ schematic = (function() { ...@@ -6196,4 +6179,3 @@ schematic = (function() {
} }
return module; return module;
}()); }());
var schematic_height = 220;
var schematic_width = 400;
var styling_height_delta = 2; //How many pixels are added to the height of the box because of styling (like a shadow)
var styling_width_delta = 2;
$(function() { $(function() {
// TODO: someone should fix all of this... // TODO: someone should fix all of this...
//$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices" //$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices"
...@@ -50,9 +45,5 @@ $(function() { ...@@ -50,9 +45,5 @@ $(function() {
editingCircuit.schematic.load_schematic(saving_circuit, ""); editingCircuit.schematic.load_schematic(saving_circuit, "");
editingCircuit.schematic.zoomall(); editingCircuit.schematic.zoomall();
if (editingCircuit.codeMirrorLine) {
editingCircuit.codeMirrorLine.replace(0, null, "circuit-schematic:" + saving_circuit);
}
}); });
}); });
...@@ -19,7 +19,7 @@ CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) { ...@@ -19,7 +19,7 @@ CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) {
, olRE = /^[0-9]+\.\s+/ , olRE = /^[0-9]+\.\s+/
, headerRE = /^(?:\={3,}|-{3,})$/ , headerRE = /^(?:\={3,}|-{3,})$/
, textRE = /^[^\[*_\\<>`]+/ , textRE = /^[^\[*_\\<>`]+/
, circuitRE = /^circuit-schematic:(.*)$/; ;
function switchInline(stream, state, f) { function switchInline(stream, state, f) {
state.f = state.inline = f; state.f = state.inline = f;
...@@ -55,43 +55,9 @@ CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) { ...@@ -55,43 +55,9 @@ CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) {
.replace(/'/g, "&#039;"); .replace(/'/g, "&#039;");
} }
var circuit_formatter = {
creator: function(text) {
var circuit_value = text.match(circuitRE)[1]
circuit_value = escapeHtml(circuit_value);
var html = "<div style='display:block;line-height:0;' class='schematic_container'><a href='#circuit_editor_modal' data-toggle='modal' class='schematic_open' style='display:inline-block;'>" +
"<input type='hidden' parts='' value='" + circuit_value + "' width='" + schematic_width + "' height='" + schematic_height + "' analyses='' class='schematic ctrls'/></a></div>";
return html;
},
size: function(text) {
return {width: schematic_width + styling_width_delta, height:schematic_height + styling_height_delta};
},
callback: function(node, line) {
try {
update_schematics();
var schmInput = node.firstChild.firstChild;
schmInput.codeMirrorLine = line;
if (schmInput.schematic) { //This is undefined if there was an error making the schematic
schmInput.schematic.canvas.style.display = "block"; //Otherwise, it gets line height and is a weird size
schmInput.schematic.always_draw_grid = true;
schmInput.schematic.redraw_background();
}
} catch (err) {
console.log("Error in edx_markdown callback: " + err);
}
}
};
function blockNormal(stream, state) { function blockNormal(stream, state) {
var match; var match;
if (stream.sol() && stream.match(circuitRE)) { if (state.indentationDiff >= 4) {
stream.skipToEnd();
return circuit_formatter;
} else if (state.indentationDiff >= 4) {
state.indentation -= state.indentationDiff; state.indentation -= state.indentationDiff;
stream.skipToEnd(); stream.skipToEnd();
return code; return code;
......
#!/usr/bin/env python
'''
Image Circuit Extension for Python-Markdown
======================================
Any single line beginning with circuit-schematic: and followed by data (which should be json data, but this
is not enforced at this level) will be displayed as a circuit schematic. This is simply an input element with
the value set to the data. It is left to javascript on the page to render that input as a circuit schematic.
ex:
circuit-schematic:[["r",[128,48,0],{"r":"1","_json_":0},["2","1"]],["view",0,0,2,null,null,null,null,null,null,null],["dc",{"0":0,"1":1,"I(_3)":-1}]]
(This is a schematic with a single one-ohm resistor. Note that this data is not meant to be user-editable.)
'''
import markdown
import re
from django.utils.html import escape
try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails
from markdown.util import etree
except:
from markdown import etree
class CircuitExtension(markdown.Extension):
def __init__(self, configs):
for key, value in configs:
self.setConfig(key, value)
def extendMarkdown(self, md, md_globals):
## Because Markdown treats contigous lines as one block of text, it is hard to match
## a regex that must occupy the whole line (like the circuit regex). This is why we have
## a preprocessor that inspects the lines and replaces the matched lines with text that is
## easier to match
md.preprocessors.add('circuit', CircuitPreprocessor(md), "_begin")
pattern = CircuitLink(r'processed-schematic:(?P<data>.*?)processed-schematic-end')
pattern.md = md
pattern.ext = self
md.inlinePatterns.add('circuit', pattern, "<reference")
class CircuitPreprocessor(markdown.preprocessors.Preprocessor):
preRegex = re.compile(r'^circuit-schematic:(?P<data>.*)$')
def run(self, lines):
def convertLine(line):
m = self.preRegex.match(line)
if m:
return 'processed-schematic:{0}processed-schematic-end'.format(m.group('data'))
else:
return line
return [convertLine(line) for line in lines]
class CircuitLink(markdown.inlinepatterns.Pattern):
def handleMatch(self, m):
data = m.group('data')
data = escape(data)
return etree.fromstring("<div align='center'><input type='hidden' parts='' value='" + data + "' analyses='' class='schematic ctrls' width='400' height='220'/></div>")
def makeExtension(configs=None):
to_return = CircuitExtension(configs=configs)
return to_return
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
from wiki.core.plugins.base import BasePlugin from wiki.core.plugins.base import BasePlugin
from wiki.core.plugins import registry as plugin_registry from wiki.core.plugins import registry as plugin_registry
from course_wiki.plugins.markdownedx import mdx_circuit, mdx_mathjax, mdx_video from course_wiki.plugins.markdownedx import mdx_mathjax, mdx_video
class ExtendMarkdownPlugin(BasePlugin): class ExtendMarkdownPlugin(BasePlugin):
...@@ -11,7 +11,7 @@ class ExtendMarkdownPlugin(BasePlugin): ...@@ -11,7 +11,7 @@ class ExtendMarkdownPlugin(BasePlugin):
This plugin simply loads all of the markdown extensions we use in edX. This plugin simply loads all of the markdown extensions we use in edX.
""" """
markdown_extensions = [mdx_circuit.CircuitExtension(configs={}), markdown_extensions = [
mdx_mathjax.MathJaxExtension(configs={}), mdx_mathjax.MathJaxExtension(configs={}),
mdx_video.VideoExtension(configs={})] mdx_video.VideoExtension(configs={})]
......
...@@ -973,57 +973,3 @@ section.wiki { ...@@ -973,57 +973,3 @@ section.wiki {
width: 100% !important; width: 100% !important;
margin-left: 0; margin-left: 0;
} }
#circuit_editor_modal.modal {
@extend %ui-depth4;
width: 648px;
margin-left: -325px;
top: 150px;
.modal-header {
h1, p {
color: $white;
}
h1 {
margin: 3px 12px 8px;
font-size: 1.1em;
}
p {
font-size: 0.9em;
margin: 5px 12px 20px;
line-height: 1em;
}
}
.modal-body {
padding-bottom: 8px;
}
.modal-footer {
margin: 12px;
}
.modal-footer .btn {
@include button(simple, #eee);
font-size: 0.8em;
margin-right: ($baseline/4);
line-height: 1.2em;
text-transform: none !important;
letter-spacing: 0 !important;
&:hover, &:focus {
color: $base-font-color;
text-decoration: none;
}
&.btn-primary {
@include button;
font-size: 0.8em;
}
margin-right: ($baseline/2);
}
}
<div align="center" id="div_wiki_circuit_${name}" class="div_wiki_circuit">
</div>
...@@ -34,10 +34,6 @@ ...@@ -34,10 +34,6 @@
{% addtoblock 'js' %} {% addtoblock 'js' %}
{% comment %} These scripts load at the bottom of the body {% endcomment %} {% comment %} These scripts load at the bottom of the body {% endcomment %}
<script>
window.onload = add_schematic_handler(window.onload);
</script>
<script src="{% static 'js/bootstrap-alert.js' %}"></script> <script src="{% static 'js/bootstrap-alert.js' %}"></script>
<script src="{% static 'js/bootstrap-collapse.js' %}"></script> <script src="{% static 'js/bootstrap-collapse.js' %}"></script>
<script src="{% static 'js/bootstrap-modal.js' %}"></script> <script src="{% static 'js/bootstrap-modal.js' %}"></script>
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
</section> </section>
<section> <section>
<h3>{% blocktrans with platform_name=settings.PLATFORM_NAME %}{{ platform_name }} Additions:{% endblocktrans %}</h3> <h3>{% blocktrans with platform_name=settings.PLATFORM_NAME %}{{ platform_name }} Additions:{% endblocktrans %}</h3>
<pre>circuit-schematic:</pre>
<pre>$LaTeX {% trans "Math Expression" %}$</pre> <pre>$LaTeX {% trans "Math Expression" %}$</pre>
</section> </section>
</div> </div>
......
...@@ -41,11 +41,6 @@ ...@@ -41,11 +41,6 @@
{% compressed_js 'application' %} {% compressed_js 'application' %}
{% compressed_js 'module-js' %} {% compressed_js 'module-js' %}
<script>
window.onload = add_schematic_handler(window.onload);
</script>
{% with mathjax_mode='wiki' %} {% with mathjax_mode='wiki' %}
{% include "mathjax_include.html" %} {% include "mathjax_include.html" %}
{% endwith %} {% endwith %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment