Exemplo n.º 1
0
        /// <summary>
        /// Start work on a chunk of text. Internally, an <see cref="XmlWriter"/> is created atop the <paramref name="writer"/>.
        /// </summary>
        public override void Start(TextWriter writer, Syntax syntax)
        {
            ArgumentValidator.ThrowIfNull(writer, "writer");

            XmlWriterSettings settings = m_xmlWriterSettings.Clone();
            settings.OmitXmlDeclaration = false;

            this.Start(XmlWriter.Create(writer, settings), syntax);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a new <see cref="Syntax" /> to the <see cref="SyntaxCatalog">syntax catalog.</see>
        /// </summary>
        /// <param name="newSyntax">New <see cref="Syntax" /> to be added. Its <see cref="Syntax.Id" /> must be unique, not taken by any other id or alias.</param>
        public static void Add(Syntax newSyntax)
        {
            ArgumentValidator.ThrowIfNull(newSyntax, "newSyntax");

            m_syntaxesLock.AcquireWriterLock(m_timeoutForSyntaxesLock);

            try {
                if (m_syntaxesByIdOrAlias.ContainsKey(newSyntax.Id)) {
                    throw new InvalidOperationException(StringExtensions.Fi("Attempt to add syntax {0} with id '{1}', but that id or alias "
                        + "is already taken by syntax '{2}'", newSyntax, newSyntax.Id, m_syntaxesByIdOrAlias[newSyntax.Id]));
                }

                m_syntaxesByIdOrAlias[newSyntax.Id] = newSyntax;
            } finally {
                m_syntaxesLock.ReleaseWriterLock();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepares for highlighting of the specified <see cref="Syntax"/>
        /// </summary>
        protected override void Start(Syntax syntax)
        {
            // SHOULD: expose XHTML strict option - we actually pass XHTML strict validation with no errors!
            #if FALSE
                this.m_writer.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", null, null);
                this.m_writer.WriteStartElement("html", "http://www.w3.org/1999/xhtml");
            #endif
            this.m_writer.WriteDocType("HTML", "-//W3C//DTD HTML 4.0 Transitional//EN", null, null);
            this.m_writer.WriteStartElement("html");

            this.m_writer.WriteStartElement("head");

            this.m_writer.WriteElementString("title", this.m_pageTitle);

            this.EmitStyleTag(syntax.Id);

            this.m_writer.WriteEndElement();

            this.m_writer.WriteStartElement("body");

            this.m_options = XhtmlOptions.Defaults;
            base.Start(syntax);
        }
Exemplo n.º 4
0
 private void Highlight(TextReader reader, TextWriter writer, Syntax syntax, string pageTitle)
 {
     ICodeFormatter formatter = this.m_arguments.UseXml ? new XmlFormatter() : new FullPageFormatter(pageTitle);
     Highlighter h = new Highlighter(syntax.Id, formatter);
     h.Highlight(reader, writer);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieves a <see cref="Syntax" /> by its id, or <see langword="null" /> if no syntax is found with that id.
        /// </summary>
        public static bool TryGetSyntaxBy(string idOrAlias, out Syntax syntax)
        {
            EnsureCatalogIsLoaded();
            ArgumentValidator.ThrowIfNullOrEmpty(idOrAlias, "idOrAlias");

            idOrAlias = idOrAlias.Trim();

            m_syntaxesLock.AcquireReaderLock(m_timeoutForSyntaxesLock);
            try {
                return m_syntaxesByIdOrAlias.TryGetValue(idOrAlias, out syntax);
            } finally {
                m_syntaxesLock.ReleaseReaderLock();
            }
        }
Exemplo n.º 6
0
 private static void LoadVimSyntaxFilesInFolder()
 {
     foreach (FileInfo file in SyntaxDirectory.GetFiles("*.vim")) {
         string id = Path.GetFileNameWithoutExtension(file.Name);
         Syntax newSyntax = new Syntax(id, id);
         SyntaxCatalog.Add(newSyntax);
     }
 }
Exemplo n.º 7
0
 private void Init(Syntax syntax, ICodeFormatter formatter)
 {
     this.m_syntax = syntax;
     this.m_scanner = this.m_syntax.BuildScanner();
     this.m_formatter = formatter;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Instantiates a new <see cref="Highlighter" /> for the given <see cref="Syntax" /> using the specified formatter
        /// </summary>
        /// <param name="syntax">Any <see cref="Syntax" /> whose syntax definition file is present, regardless of whether it's in the <see cref="SyntaxCatalog" />.</param>
        /// <param name="formatter">The <see cref="ICodeFormatter">formatter</see> to be used for the output generation.</param>
        public Highlighter(Syntax syntax, ICodeFormatter formatter)
        {
            ArgumentValidator.ThrowIfNull(syntax, "syntax");
            ArgumentValidator.ThrowIfNull(formatter, "formatter");

            this.Init(syntax, formatter);
        }
Exemplo n.º 9
0
 /// <summary>
 /// And so he got inside his mind, day and night, and he'd write
 /// </summary>
 public void Start(XmlWriter writer, Syntax syntax)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// When he first started mic respect's what he was after (af-ter)
 /// </summary>
 public void Start(TextWriter writer, Syntax syntax)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// Prepares for highlighting of the specified <see cref="Syntax" />
 /// </summary>
 protected virtual void Start(Syntax syntax)
 {
     this.m_writer.WriteStartElement("code");
     this.m_writer.WriteAttributeString("syntax", syntax.ToString());
 }
Exemplo n.º 12
0
        /// <summary>
        /// Start work on a chunk of text with output to a <see cref="XmlWriter"/>.
        /// </summary>
        public void Start(XmlWriter writer, Syntax syntax)
        {
            ArgumentValidator.ThrowIfNull(writer, "writer");
            ArgumentValidator.ThrowIfNull(syntax, "syntax");

            this.m_writer = writer;
            this.m_mode = HighlightMode.Unknown;
            this.m_hasStartedMode = false;
            this.m_charBuf = new char[CharBufferSize];

            this.Start(syntax);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Start work on a chunk of text. Internally, an <see cref="XmlWriter" /> is created atop the <paramref name="writer"/>.
        /// </summary>
        public virtual void Start(TextWriter writer, Syntax syntax)
        {
            ArgumentValidator.ThrowIfNull(writer, "writer");

            this.Start(XmlWriter.Create(writer, m_xmlWriterSettings), syntax);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Prepares for highlighting of the specified <see cref="Syntax"/>
        /// </summary>
        protected override void Start(Syntax syntax)
        {
            if (this.m_options.EmitStyleTag) {
                this.EmitStyleTag(syntax.Id);
            }

            this.m_classNames = CssScheme.LongCssClassNamesForModes;

            this.m_writer.WriteRaw("<table cellpadding='0' cellspacing='0' class='irisContainer' style='border-collapse: collapse; border-spacing:0'");

            this.m_writer.WriteRaw("><tbody><tr><td style='margin: 0; padding:0'></td>");
            this.m_writer.WriteRaw(this.m_options.NewLineChars);

            //			if (this.m_options.EmitToolbar) {
            //				this.m_writer.WriteRaw("<td class='toolBar'> <span class='irisLogo'>color by iris</span> <span>select</span> | <span>view plain</span> </td> </tr>	<tr> <td></td>");
            //			}

            this.m_writer.WriteRaw("<td rowspan='2' class='highlighted output'>");
            this.m_writer.WriteStartElement("pre");
            this.m_writer.WriteAttributeString("class", syntax.Id + " " + "highlighted");

            this.m_writer.WriteStartElement("span");
            this.m_writer.WriteAttributeString("class", this.m_classNames[(int) HighlightMode.Normal]);

            this.m_cntLines = 1;
        }
Exemplo n.º 15
0
 /// <summary>
 /// And so he got inside his mind, day and night, and he'd write
 /// </summary>
 public void Start(XmlWriter writer, Syntax syntax)
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// When he first started mic respect's what he was after (af-ter)
 /// </summary>
 public void Start(TextWriter writer, Syntax syntax)
 {
 }