예제 #1
0
 private void LoadHtmlSource(Stream stream)
 {
     stream.Position = 0;
     byte[] bytes = NStreamHelpers.ReadToEnd(stream);
     m_HtmlTextBox.Text = NEncoding.UTF8.GetString(bytes);
 }
예제 #2
0
        /// <summary>
        /// Analyzes the given stream of C# code, highlights it syntax and returns
        /// the resulting HTML and CSS code as a stream.
        /// </summary>
        /// <param name="csStream"></param>
        /// <returns></returns>
        public Stream Highlight(Stream csStream)
        {
            int byteIndex = 0;

            byte[] data = NStreamHelpers.ReadToEnd(csStream);
            if (data.Length > 3 && data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF)
            {
                // The data starts with a BOM
                byteIndex = 3;
            }

            m_Chars         = NEncoding.UTF8.GetChars(data, byteIndex, data.Length - byteIndex);
            m_StartPosition = 0;
            m_Position      = 0;
            m_EndPosition   = m_Chars.Length - 1;
            m_TokenStartPos = 0;
            m_Output        = new StringBuilder();

            char c;

            while (ReadChar(out c))
            {
                if (IsLetter(c) || c == '_')
                {
                    continue;
                }

                if (c == Slash)
                {
                    // This is a comment
                    ReadAfterSlash();
                    continue;
                }
                else if (c == SingleQuot || c == DoubleQuot)
                {
                    // This is a string literal
                    string str;
                    if (ReadTo(c, Backslash, out str))
                    {
                        OnString(c + str + c);
                        ReadChar(out c);
                        m_TokenStartPos = m_Position;
                    }
                    continue;
                }

                if (m_TokenStartPos < m_Position - 1)
                {
                    // Add a token
                    string token = new String(m_Chars, m_TokenStartPos, m_Position - 1 - m_TokenStartPos);
                    OnToken(token);
                }

                OnDelimiter(c);
                m_TokenStartPos = m_Position;
            }

            // Add the last token
            if (m_TokenStartPos < m_Position)
            {
                string token = new String(m_Chars, m_TokenStartPos, m_Position - m_TokenStartPos);
                OnToken(token);
            }

            // Create and return the result
            string stylesheet;
            string codeStyle;

            if (m_bInlineStyles)
            {
                stylesheet = String.Empty;
                codeStyle  = " style=\"" + CodeStyle + "\"";
            }
            else
            {
                stylesheet = StyleSheet;
                codeStyle  = String.Empty;
            }

            string output = HtmlTemplate.Replace("{STYLESHEET}", stylesheet);

            output = output.Replace("{CODE_STYLE}", codeStyle);
            output = output.Replace("{GENERATED_HTML}", m_Output.ToString());

            byte[] bytes = NEncoding.UTF8.GetBytes(output);
            return(new MemoryStream(bytes));
        }
예제 #3
0
 public void OnItemDecompressed(NZipItem zipItem)
 {
     byte[] bytes = NStreamHelpers.ReadToEnd(zipItem.Stream);
     m_ImageMap.Add(zipItem.Name, bytes);
 }